I have environment variables set in Railway but they are not showing available in my app

cpxx9
HOBBY

7 months ago

I have set env variables in Railway, but in my Node app I cannot see them.

I have all the pre-made variables, as shown in the log (i console logged all process.env), but none of the Ones I added myself

/app/node_modules/passport-jwt/lib/strategy.js:45

    throw new TypeError('JwtStrategy requires a secret or key');

    ^

TypeError: JwtStrategy requires a secret or key

at new JwtStrategy (/app/node_modules/passport-jwt/lib/strategy.js:45:15)

at module.exports (/app/config/passport.js:17:5)

at Object. (/app/routes/usersRouter.js:2:30)

at Module._compile (node:internal/modules/cjs/loader:1364:14)

at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)

at Module.load (node:internal/modules/cjs/loader:1203:32)

at Module._load (node:internal/modules/cjs/loader:1019:12)

at Module.require (node:internal/modules/cjs/loader:1231:19)

at require (node:internal/modules/helpers:177:18)

at Object. (/app/routes/indexRouter.js:2:25)

Node.js v18.20.5

npm warn config production Use --omit=dev instead.

> blog-api@1.2.0 start

> node app.js

{

NPMCONFIGPRODUCTION: 'false',

LIBRARY_PATH: '~/.nix-profile/lib:',

RAILWAYREPLICAREGION: 'us-west2',

RAILWAYREPLICAID: '5cb0425b-75e0-44f7-94b7-df3fa7cffaa0',

USER: 'root',

npmconfiguser_agent: 'npm/10.8.2 node/v18.20.5 linux x64 workspaces/false',

CI: 'true',

HOSTNAME: '5c3653d060e6',

RAILWAYGITAUTHOR: 'cpxx9',

npmnodeexecpath: '/nix/store/bzi3zjxiblnf4gzfhsn2i96rl07kxi5n-nodejs-18.20.5/bin/node',

GITSSLCAINFO: '/etc/ssl/certs/ca-certificates.crt',

SHLVL: '0',

LDLIBRARYPATH: ':/usr/lib',

npmconfignoproxy: '',

RAILWAYGITBRANCH: 'main',

PORT: '8080',

RAILWAYGITCOMMIT_SHA: 'bbf2096246617cc05307f800cb60e14f6815a9db',

HOME: '/root',

QTDIR: '~/.nix-profile:',

RAILWAYGITREPO_NAME: 'odin-blog-backend',

npmpackagejson: '/app/package.json',

CPATH: '~/.nix-profile/include:',

NIXPKGSALLOWBROKEN: '1',

NIX_PROFILES: '/nix/var/nix/profiles/default /root/.nix-profile',

NODE_ENV: 'production',

RAILWAYSERVICENAME: 'odin-blog-backend',

BUILDKITDOCKERFILECHECK: 'skip=all',

npmconfiguserconfig: '/root/.npmrc',

INIT_CWD: '/app',

View Deploy details

> ⓘ Deployment information is only viewable by project members and Railway employees.

1 Replies

7 months ago

Hello,

The DATABASE_URL should not be a shared variable, I've undone this setting for you.

You also had your start command set to npx prisma migrate dev --name init this caused the migration to run but never starts the server, I've moved npx prisma migrate dev --name init into a pre-deploy command, and set your start command to node app.js

And finally, you didn't have a domain attached to the service, so I clicked Generate Domain for you.

With all these changes, your deployment is active and accepting HTTP requests!

Best,
Brody