Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript User Authentication With Express and Mongo What is Authentication? Setting Up the Project

Tennyson Horn
Tennyson Horn
14,660 Points

npm start fails w/out first booting the mongo server in a separate tab.

In the video, the teacher simply runs npm start in the finished project root. If I attempt to do so, I get a deprecation warning from node and an error log as below:

^C(username) on Users-MacBook-Pro @ complete: npm start

> treehouse-express-auth@1.0.0 start /Users/username/MyFilePathHere/JavaScript-user-auth-express/complete
> node ./app

(node:47508) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
Express app listening on port 3000
connection error: { MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
    at Pool.<anonymous> (/Users/username/MyFilePathHere/JavaScript-user-auth-express/complete/node_modules/mongodb-core/lib/topologies/server.js:336:35)
    at emitOne (events.js:116:13)
    at Pool.emit (events.js:211:7)
    at Connection.<anonymous> (/Users/username/MyFilePathHere/JavaScript-user-auth-express/complete/node_modules/mongodb-core/lib/connection/pool.js:280:12)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at Socket.<anonymous> (/Users/username/MyFilePathHere/JavaScript-user-auth-express/complete/node_modules/mongodb-core/lib/connection/connection.js:189:49)
    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)
  name: 'MongoError',
  message: 'failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]' }

However, if I open another tab and boot up the mongo server with mongod, then go back and run npm start in the original tab, it throws the same deprecation warning but runs properly otherwise. See below:

^C(username) on Users-MacBook-Pro @ complete: npm start

> treehouse-express-auth@1.0.0 start /Users/username/MyFilePathHere/JavaScript-user-auth-express/complete
> node ./app

(node:47718) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
Express app listening on port 3000

Does anyone know why I have to start the server first instead of just running npm start like in the video? Does the lesson just skip showing the server start up assuming that we would already know to do so?

2 Answers

Neil McPartlin
Neil McPartlin
14,662 Points

Hi Tennyson. Your findings are correct.

1: The deprecation message is simply an early warning that alternative coding needs to be found, because the current code being used will 'eventually' stop working. For the duration of this Treehouse lesson, it probably will not matter, but had you been planning to go live with such warning messages, you would be wise to follow the advise given and incorporate the updated coding replacement.

2: Yes, the onus is on us to manually start the Mongo DB daemon (mongod.exe), before we run 'npm start' in a second command line tab. In this project, NPM is handling the creation of the website (using Express), so when you run 'npm start', you are actually running the 'start' entry that can be found in the package.json file. NPM helps us to install the packages (like Mongoose), which communicates with the Mongo DB, but it does not get involved with installing and starting Mongo DB itself.

Tennyson Horn
Tennyson Horn
14,660 Points

Thanks! Just wanted to make sure I wasn't missing something fundamental going into this.

Gabbie Metheny
Gabbie Metheny
33,778 Points

Based on the path listed when you run npm start, it looks like you were using the completed project files, rather than the starter files. In the downloaded zip file, you should be starting from the code in the S1V4 folder. If your app is trying to do anything related to Mongo at this point in the course, you're probably on the wrong set of files and will run into some errors.