Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Web Technology by (50.2k points)

I'm new in nodeJS, started learning by following a trailer on youtube, everything goes well until I added the connect function if mongodb,


when I run my code on cmd (node start-app), get the following error,

MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED]

Could someone explain to me which step I missed? my code :

var express = require("express");

var MongoClient = require('mongodb');

var url = "mongodb://localhost:27017/mydb";

var webService = require("./webService");

var server = express();

MongoClient.connect(url, function (err, db) {

    if (err) throw err;

    console.log("Database created!");



server.use(express.urlencoded({ extended: true }));

server.set('views', __dirname);

server.get('/', function (request, response) {

    response.sendFile(__dirname + '/MainPage.html');


server.get('/Sign', function (request, response) {

    response.render(__dirname + '/Sign.ejs');

});"/signUp", webService.signUp);"/createUser", webService.createUser);


1 Answer

0 votes
by (108k points)

You have to first install the MongoDB database server first in your system and start it.

Use the below link to install MongoDB

Related questions

0 votes
1 answer
0 votes
2 answers
asked Sep 13, 2019 in SQL by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories