Npm install OK, but npm start causes URI malformed error

Hello,

On a fresh mflix-js folder on Windows:
npm start fails on unmodified project.
Installation seems to go smoothly but when trying to start mflix with npm start I get the bellow error.
I tried to do an npm rebuild but no change.
The error is quite criptic with the first error link sending me to a node file instead of a project file.

nodemon -L ./index.js

[nodemon] 1.19.1
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node ./index.js
MongoParseError: URI malformed, cannot be parsed
at parseConnectionString (C:\Users\lvignals\WebstormProjects\MongoDBPorjects\m220\mflix-js\node_modules\mongodb\lib\core\uri_parser.js:502:21)
at connect (C:\Users\lvignals\WebstormProjects\MongoDBPorjects\m220\mflix-js\node_modules\mongodb\lib\operations\connect.js:266:3)
at ConnectOperation.execute (C:\Users\lvignals\WebstormProjects\MongoDBPorjects\m220\mflix-js\node_modules\mongodb\lib\operations\connect.js:191:5)
at C:\Users\lvignals\WebstormProjects\MongoDBPorjects\m220\mflix-js\node_modules\mongodb\lib\operations\execute_operation.js:109:26
at new Promise ()
at executeOperation (C:\Users\lvignals\WebstormProjects\MongoDBPorjects\m220\mflix-js\node_modules\mongodb\lib\operations\execute_operation.js:102:10)
at MongoClient.connect (C:\Users\lvignals\WebstormProjects\MongoDBPorjects\m220\mflix-js\node_modules\mongodb\lib\mongo_client.js:216:10)
at Function.MongoClient.connect (C:\Users\lvignals\WebstormProjects\MongoDBPorjects\m220\mflix-js\node_modules\mongodb\lib\mongo_client.js:379:22)
at Object.connect (C:\Users\lvignals\WebstormProjects\MongoDBPorjects\m220\mflix-js\src/index.js:23:13)
at Module._compile (internal/modules/cjs/loader.js:776:30)
[nodemon] app crashed - waiting for file changes before starting…

Hey @Lu_57807

Have you updated the appropriate .env file? And if so check your Mongo uri.

Hi!

I did a copy past from Atlas as in:

MFLIX_DB_URI=mongodb+srv://m220student:m220password@[hidden-for-discourse].azure.mongodb.net/test?retryWrites=true&w=majority

The white-listing is set 0.0.0.0/0 and I can connect from the local mongoshell
Is there anything else I should have updated?

Doing:
console.log(process.env.MFLIX_DB_URI);
in:
src/index.js
returned undefined on the console?

How about renaming the file?

Yes that was it.
There was no file extension, at first I used this after reading about the dotenv module:
require("dotenv").config({path:'./dotenv_win'});
That worked, but I still did not know what the original issue was, if I rename the file dotenv_win file to dotenv_win.env then it works without adding a file path parameter to the code.

Many thanks, and have a great day :slight_smile:

It is suppose to be only named .env

The dot means it is a hidden file.

Did you look over the README.rst file it has the following instruction.

When you’ve edited the file, rename it to .env with the following command:

  mv dotenv_unix .env  # on Unix
  ren dotenv_win .env  # on Windows

I had the same issue just following the video. I wish he would show this setup in the video.

Funny but I found those steps included in a doc that comes after the video… It is looking like a good training with a nice and complete sample app :slight_smile: I like what they have done and prepared for us.
Good luck with the training!

1 Like