Clint Whaley
Clint Whaley

Reputation: 479

error in running a node js file

Whenever I run my index.js file on webstorm, I get the following error:

process.nextTick(function() { throw err; })
                                      ^
Error: connect ECONNREFUSED 127.0.0.1:27017
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)

Process finished with exit code 1

This is my index.js file:

var express = require('express');
var app = express();

var bodyParser = require('body-parser');

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/cats');

app.use (bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: true
}));

var cats = require('./cat_routes.js')(app);

var server = app.listen(3000, function(){
    console.log('running at 3000');
});

I am learning side by side with some tutorials, but this is a very strange error that I don't really understand.

Upvotes: 0

Views: 1200

Answers (1)

SiddAjmera
SiddAjmera

Reputation: 39482

Make sure your MongoD instance is running.

If it's not open command prompt and type in mongod to start it. I assume that you have added path to your MongoDB installation dir. in your PATH ENVIRONMENT VARIABLE.

Also change your index.js file to this :

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/cats');
app.use (bodyParser.json());

app.use(bodyParser.urlencoded({
    extended: true
}));

var cats = require('./cat_routes.js')(app);

var server = app.listen(3000, function(){
    console.log('running at 3000');
});

Upvotes: 1

Related Questions