-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
when using dotenv error - URL malformed, cannot be parsed #9
Comments
the problem is not with mongoose or dotenv it has to do with the way you are initializing dotEnv package. 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. |
@nickhq thanks a lot, was a stupid mistake I was doing. I can confirm your suggestion works. |
Awesome! You can go ahead and close it now |
@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
Because in staging/production environments I don't need dotenv at all. |
this is awesome, thanks for the heads up.
[image: MailTag] Sent with MailTag <https://www.mailtag.io>
…On Thu, Jul 5, 2018 at 6:13 PM Artjom Zabelin ***@***.***> wrote:
@mtziyo <https://github.com/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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AO_26OLRtKiAJag03E1gh36gJOubQNsOks5uDiz9gaJpZM4TN9Gz>
.
|
hey @artjomzab, this is a nice approach thanks for sharing :) |
following the guide on the official nestjs docs, when trying to load a db connection string via a dotenv file, a error is thrown "URL malformed, cannot be parsed".
e.g.
dotenv file
db_connection = 'mongodb://localhost:27017/foo'
root.module
@ module({
modules: [
MongooseModule.forRoot(process.env.db_connection),
....
],
})
not sure if this is an implementation error from my part.
thanks,
The text was updated successfully, but these errors were encountered: