0

This is my db.js:

import mongoose from 'mongoose';
export default () => {
 mongoose.Promise = global.Promise;
 mongoose.connect('mongodb://localhost/meetupapp');
 mongoose.connection
     .once('open', () => console.log('Mongodb running'))
    .on('error', err => console.error(err));
};

and this is the error message: MongoError: failed to connect to server [localhost:27017] on first connect] name: 'MongoError

I've installed mongodb!

Denis Doan
  • 73
  • 1
  • 8
  • 1
    Did you start "mongod"? – Abrikot Jun 08 '17 at 11:07
  • 1
    Possible duplicate of [\[Error: failed to connect to \[localhost:27017\]\] from NodeJS to mongodb](https://stackoverflow.com/questions/24710490/error-failed-to-connect-to-localhost27017-from-nodejs-to-mongodb) – GilZ Jun 08 '17 at 11:12

1 Answers1

0

Verify your mongodb engine is running or not

WINDOWS

1.) Open command prompt 2.) Type mongo

if it works that means mongod is running or else you have to start it manually

COMMAND

mongod --dbpath [path-of-your-database]

create folder where you want to store the database and assign that folderpath in --dbpath

Ex "c:/mongo/db/"

and then try mongo command and it will work..

LINUX

COMMAND

1.) sudo service mongod start

MAC

After installing mongodb

COMMAND

1.) export PATH=<mongodb-install-directory>/bin:$PATH  [Setting the environment variable]
2.) mkdir -p /data/db   [creating directory for data to store]
3.) mongod --dbpath [path-of-your-database]
Shivam Mishra
  • 1,826
  • 1
  • 11
  • 16