Comments (6)
the problem is not with mongoose or dotenv it has to do with the way you are initializing dotEnv package.
Please ensure that on the file where you are creating the mongoose connection you are also requiring dotEnv.
require('dotenv').config()
after that line the you can now initialized mongoose
mongoose.connect(process.env.MONGO_URI)
.then(connection => {
console.log('Connected to MongoDB')
})
.catch(error => {
console.log(error.message)
})
hope that helps.
from mongoose.
@nickhq thanks a lot, was a stupid mistake I was doing. I can confirm your suggestion works.
from mongoose.
Awesome! You can go ahead and close it now
from mongoose.
@mtziyo the issue is describe here in more detail https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
I like the approach of removing dotenv.config from my project and adding following script to package.json
"start:local": "ts-node --require dotenv/config -r tsconfig-paths/register src/server.ts"
Because in staging/production environments I don't need dotenv at all.
from mongoose.
from mongoose.
hey @artjomzab, this is a nice approach thanks for sharing :)
from mongoose.
Related Issues (20)
- Support compound index in @Schema decorator HOT 1
- Unexpected ref function behaviour HOT 1
- OverwriteModelError: Cannot overwrite `X` model once compiled. HOT 2
- @Prop() schemaType on Map not working HOT 3
- findOneAndUpdate fails with multi arrayFilters in nested arrays HOT 1
- Unable to connect for non-SSL connections when specifying dbName in URI HOT 1
- Update mongoose to v8 HOT 2
- InjectModel decorator for multiple databases is broken since version 9.1.0 HOT 1
- When set connectionName to useClass, Populate Error: Schema hasn't been registered for model HOT 1
- Injecting services into MongooseModule.forFeatureAsync not triggering the middleware hooks HOT 1
- @Prop() schemaType on Map not working.
- IntersectionType and Prop decorator HOT 2
- Nest can't resolve dependencies using yarn berry workspaces HOT 1
- Unable to use 'connectionName' with forRootAsync initialization HOT 1
- Cannot populate using a dynamic ref inside an array of embedded discriminators HOT 1
- MongoDB Connections not Closing HOT 1
- type unknown and any HOT 1
- Cannot convert undefined to a BigInt HOT 2
- Mongo connection count rises very high
- allow nestjs application to start even if MongoDB is temporarily unavailable. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose.