Error while following "How to Use MERN Stack: A Complete Guide"

I was following the “How to Use MERN Stack: A Complete Guide” and got stuck at the Server API Endpoints section. How To Use MERN Stack: A Complete Guide | MongoDB

I am getting the following error when I try running “node server.mjs”

            throw new MongoParseError('Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"');

MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
    at new ConnectionString (/Users/name/Desktop/mern/server/node_modules/mongodb-connection-string-url/lib/index.js:86:19)
    at parseOptions (/Users/name/Desktop/mern/server/node_modules/mongodb/lib/connection_string.js:191:17)
    at new MongoClient (/Users/name/Desktop/mern/server/node_modules/mongodb/lib/mongo_client.js:48:63)
    at file:///Users/name/Desktop/mern/server/db/conn.mjs:10:16
    at (node:internal/modules/esm/module_job:194:25)

Node.js v19.4.0

I have followed the tutorial completely as I am very new to MERN, so I am not sure what I am doing wrong as my code is the same as in the tutorial.

Check your ATLAS_URI
Can you connect to your mongodb from the shell using above connect string?

My ATLAS_URI has the correct connection string in config.env



But when I call process.env.ATLAS_URI in conn.mjs it returns undefined


import { MongoClient } from "mongodb";

const connectionString = process.env.ATLAS_URI || "";

const client = new MongoClient(connectionString);

let conn;

try {

conn = await client.connect();

} catch(e) {



let db = conn.db("sample_training");

export default db;

Can you connect by shell?You did not respond on this
Did you replace userid and password without these <…>
Any special characters in your password?
May be space needed before and after equal sign? Like ATLAS_URI =