Cant access Enviroment Variables Nest js

ror2022
HOBBY

a year ago

I don't understand why I can't access to my enviroment variables in my project Nest js, got this:

[Nest] 27 - 07/03/2024, 2:50:39 PM ERROR [MongooseModule] Unable to connect to the database. Retrying (8)...

Jul 03 08:50:42

servercornerstore

[Nest] 27 - 07/03/2024, 2:50:42 PM ERROR [MongooseModule] Unable to connect to the database. Retrying (9)...

Jul 03 08:50:42

servercornerstore

[Nest] 27 - 07/03/2024, 2:50:42 PM ERROR [ExceptionHandler] The uri parameter to openUri() must be a string, got "undefined". Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string.

Jul 03 08:50:42

servercornerstore

MongooseError: The uri parameter to openUri() must be a string, got "undefined". Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string.

Jul 03 08:50:42

servercornerstore

at NativeConnection.createClient (/app/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:219:11)

Jul 03 08:50:42

servercornerstore

at NativeConnection.openUri (/app/node_modules/mongoose/lib/connection.js:822:34)

Jul 03 08:50:42

servercornerstore

at Mongoose.createConnection (/app/node_modules/mongoose/lib/mongoose.js:373:10)

Jul 03 08:50:42

servercornerstore

at Function.createMongooseConnection (/app/node_modules/@nestjs/mongoose/dist/mongoose-core.module.js:114:37)

Jul 03 08:50:42

servercornerstore

at /app/node_modules/@nestjs/mongoose/dist/mongoose-core.module.js:65:123

Jul 03 08:50:42

servercornerstore

at Observable._subscribe (/app/node_modules/rxjs/src/internal/observable/defer.ts:55:15)

Jul 03 08:50:42

servercornerstore

at Observable._trySubscribe (/app/node_modules/rxjs/src/internal/Observable.ts:244:19)

Jul 03 08:50:42

servercornerstore

at /app/node_modules/rxjs/src/internal/Observable.ts:234:18

Jul 03 08:50:42

servercornerstore

at Object.errorContext (/app/node_modules/rxjs/src/internal/util/errorContext.ts:29:5)

This is my repo:

https://github.com/ROR2022/servercornerstore

7 Replies

Are they defined at Railway or only in your .env file?


ror2022
HOBBY

a year ago

Are they defined at Railway or only in your .env file?

Yes they are...


Have a look at this basic implementation. Probably is the best way to share your variables inside your app in railway. https://github.com/allen-n/nestjs-generic


a year ago

It would not be best to include variables in the repo, that is very insecure, please only ever use service variables.


Status changed to Solved railway[bot] 12 months ago


windel
PRO

a year ago

do you use dotenv.config()?


ror2022
HOBBY

a year ago

thanks, I've finally seen my error.


ror2022

thanks, I've finally seen my error.

godfred-owusu
FREE

2 months ago

How did you solve it, I am having the same issue


Status changed to Open railway[bot] 3 months ago


Cant access Enviroment Variables Nest js - Railway Help Station