Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Hi, I try to do a Mern Stack authentification and it's been 2 weeks since I can't solve this error

Error says: Server running on port 5000 Error: MongooseError: The uri parameter to openUri() must be a string, got "undefined". Make sure the first parameter to mongoose.connect() or mongoose.crea teConnection() is a string. [nodemon] app crashed - waiting for file changes before starting...

This is my server.js:

require ("dotenv").config({path: '../config.env' });
const express = require('express');
const connectDB = require('./config/db');

//Connect DB
connectDB();

const app = express();

app.use(express.json());

app.use('/api/auth', require('./routes/auth'));

const PORT = process.env.PORT || 5000;


const server = app.listen(PORT, () => console.log(`Server running on port ${PORT}`));

process.on("unhandledRejection", (err, promise) => {
    console.log(`Logged Error: ${err}`);
    server.close(() => process.exit(1));
})

This is my db.js:

const mongoose = require('mongoose');

const connectDB = async() => {
      await mongoose.connect(process.env.MONGO_URI, {
            useNewUrlParser: true,
            useCreateIndex: true,
            useUnifiedTopology: true,
            useFindAndModify: true
        });

        console.log("MongoDB connected");
    };

module.exports = connectDB;

And this is my config.env file:

PORT=5000;

MONGO_URI=mongodb://localhost:27017/mernauth
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your code is not able to read the env file properly.

  1. It looks like your dotenv is not imported correctly.
  2. First try to console log process.env.

Try to import dotenv as:

require('dotenv').config()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!