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

215
Views
MongoDB Atlas connectivity with Node does not work

I am trying to connect and run Node.js server and connect to collection on MongoDB Atlas. Howewer, I am geting crash in line where I should get connection response. Please advise:

Node

.env file:

 MOVIEREVIEWS_DATABASE_URI=mongodb+srv://<user>:<password>@cluster0.wvtv6.mongodb.net/sample_mflix?retryWrites=true&w=majority
MOVIEREVIEWS_NS=sample_mflix

Index.js:

import express from 'express';
import cors from 'cors';
import MoviesRoute from './api/MoviesRoute.js';
import dotenv from 'dotenv';
import mongodb from 'mongodb';


class Index {
    static app = express();
    static router = express.Router();
    static main() {
        dotenv.config();
        Index.setUpServer();
        Index.setUpDatabase();
    }

    static setUpServer() {
        Index.app.use(cors());
        Index.app.use(express.json());
        Index.app.use('/api/v1/movies', 
        MoviesRoute.configRoutes(Index.router));
        Index.app.use('*', (req, res) => { res.status(404).json({ error: 'not found' }); });
    }

    static async setUpDatabase() {
        const client = new mongodb.MongoClient(process.env.MOVIEREVIEWS_DB_URI);
        const port = process.env.PORT || 8000;
        try { // Connect to the MongoDB cluster 
            await client.connect();
            Index.app.listen(port, () => {
                console.log(`server is running on port:${port}`);
    
            });
        }
        catch (e) {
             console.error(e); process.exit(1); }
    }
}
Index.main();

I cannot figure out what is missing :(

about 4 years ago · Juan Pablo Isaza
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!