Reputation: 480
I am getting this error when I start my node server; I am using Git Bash in windows.
(node:1636) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
at Pool.<anonymous> (C:\Users\nikac\Desktop\js\myapp\node_modules\mongodb-core\lib\topologies\server.js:564:11)
at emitOne (events.js:116:13)
at Pool.emit (events.js:211:7)
at Connection.<anonymous> (C:\Users\nikac\Desktop\js\myapp\node_modules\mongodb-core\lib\connection\pool.js:317:12)
at Object.onceWrapper (events.js:317:30)
at emitTwo (events.js:126:13)
at Connection.emit (events.js:214:7)
at Socket.<anonymous> (C:\Users\nikac\Desktop\js\myapp\node_modules\mongodb-core\lib\connection\connection.js:246:50)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
(node:1636) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1636) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Here is my server file:
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
// set up express app
const app = express();
// connect to mongodb
mongoose.connect('mongodb://localhost:27017/recipego', { useNewUrlParser: true });
mongoose.Promise = global.Promise;
app.use(bodyParser.json());
app.use('/api', require('./routes/api'));
app.listen(8999, function () {
console.log('App listening on port 8999!')
});
I googled many times, but did not find proper solution that helped me. I tried commands like mongo & mongod, but they do not work neither in my Git Bash nor in WinCmd.
Upvotes: 1
Views: 2485
Reputation: 778
Your code seems to be ok.Make sure that mongo is running.go to your mongo installation directory and find the mongod.exe file .double click it to execute it.To use mongod in comand line you will have to add the path of the mongod.exe to your environmental variables
Upvotes: 1