Skip to content

pm2 startup sequence fails #1

Closed

Description

@ewingson

https://github.com/serverproject-dev/solidweb.app/blob/main/debug/config.json

works,
whereas

https://github.com/serverproject-dev/solidweb.app/blob/main/debug/ecosystem.config.js

does not work.

error from pm2:

2026-04-21 15:41:20 +00:00: SECURITY ERROR: TOKEN_SECRET environment variable must be set in production
2026-04-21 15:41:20 +00:00: Generate one with: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

I do not have node command yet for now as user jss, but nvm and node 24.xy are present

Activity

  1. melvincarvalho commented on Apr 21, 2026

    @melvincarvalho

    Diagnosis

    The difference is NODE_ENV:

    • config.json works because pm2 isn't started with --env production, so NODE_ENV stays unset. JSS falls through to a dev path: generates a random secret per process and logs a warning (tokens don't survive restarts, but the server runs).
    • ecosystem.config.js sets env_production: { NODE_ENV: 'production' }. With NODE_ENV=production and no TOKEN_SECRET, JSS exits on purpose (src/auth/token.js hard-fails to force the operator to pick a stable secret).

    Quick fix (3 steps, no node needed)

    1. Generate a 64-hex-char secret:
      openssl rand -hex 32
    2. Paste it into ecosystem.config.js:
      env_production: {
        NODE_ENV: 'production',
        TOKEN_SECRET: 'paste-64-hex-chars-here',
        PATH: '/home/jss/.nvm/versions/node/v24.11.0/bin:' + process.env.PATH,
      },
    3. Restart:
      pm2 restart jss --update-env

    Committing a secret directly to the repo isn't best-practice long-term — once it works, you can move it to a root-owned /etc/jss/token.secret file sourced by a small wrapper, or an env_file. But for a first working deployment, the inline value is the minimum-friction path.

    Upstream

    Filed JavaScriptSolidServer/JavaScriptSolidServer#280 to make JSS auto-generate and persist a secret on first run — so new operators don't hit this at all. Once that lands you won't need any of the above.

  2. ewingson commented on Apr 22, 2026

    @ewingson
    MemberAuthor

    close 2026-04-22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions