MERN Stack Tutorial

Hello i’m following this official MERN Stack tutorial : How To Use MERN Stack: A Complete Guide | MongoDB.

But i’m stuck right after the command “nodemon server” wich throw in terminal an error in node_modules folders and file: mongodb-connection-string-url/lib/index.js:64 : const match = uri.match(HOSTS_REGEX);

TypeError: Cannot read property ‘match’ of undefined

Which seems normal as the “uri” in constructor function line 62 seems undefined ( if i had a console.log to check it ) .
Where could it come from ?

I’m pretty sure my ATLAS_URI in config.env is ok with right username and password ( no special character in it ) and follows the official format.

Any ideas what i missed ? Is the tutorial still up to date ? Does anything have changed lately in the packages used that could cause this error ?

Thanx in advance for your help with a newbie in MERN

2 Likes

Hi @Julien_Desmettre , and welcome!

It’s been a while since you posted your post, have you solved the issue ?

The error message above indicates that the ATLAS_URI passed into MongoClient constructor on db/conn.js file is undefined.

I could reproduce the error above if I purposely altered the tutorial code example in db/conn.js to fail on line 2 (mongodb-connection-string-url version 2.1.0)

You could try adding a line in db/conn.js file to check whether the ATLAS_URI environment variable is indeed defined:

const Db = process.env.ATLAS_URI;
if (Db === undefined) { throw new Error("My ATLAS_URI is undefined");}

The ATLAS_URI variable should be defined in config.env file, and the file should be inside of the server folder :

└── server
    ├── config.env
    ├── db
    │   └── conn.js
    ├── node_modules
    ├── package-lock.json
    ├── package.json
    ├── routes
    └── server.js

Regards,
Wan.

1 Like

Hi @wan ,
indeed it’s been a while since this first tutorial. I’ve jumped to other examples, courses and tutorials since.
But I’ve taken some time to read you and to check this back now. The problem was really simple to solve and if I’d downloaded the github repo to check ( what I do now every time I follow a new example ) I’d noticed what you suggested, to know, that the config.env file has to be in the server repo, what seems obvious for trained users, but what wasn’t for me as a newbie.

Thanks a lot for your answer ad your time. Hope that this topic will help other newbie making some basic mistakes :slight_smile:

Regards

Julien

2 Likes

“the config.env file has to be in the server repo”, I’ve created it in the root repo.

Hi @Julien_Desmettre ,

I’m glad you’ve managed to solve the issue as well.

Regards,
Wan.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.