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 User Registration Using Nodemon While Developing an Express App

npm bugs treehouse-express-auth. I can't get the app to run on the localhost:3000 server.

when I installed nodemon, it still wouldn't run the app. It keeps giving me this error: Error: Cannot find module 'mongoose' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (/Users/Cynthia/Documents/treehouse/node_authentication_app/app.js:3:16) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) [nodemon] app crashed - waiting for file changes before starting...

9 Answers

James Churchill
STAFF
James Churchill
Treehouse Teacher

Cynthia,

Hi there! Based upon the error message that you shared, it sounds like you're attempting to load the mongoose module but you don't have it installed yet. Did you run the command npm install mongoose before attempting to load the module using require('mongoose')?

Thanks ~James

Hi James,

I installed Mongoose, thanks. Then, I ran nodemon following the video and it said that I don't have module-connect. Here is my error message:setups-MacBook-Pro:node_authentication_app Cynthia$ nodemon [nodemon] 1.18.9 [nodemon] to restart at any time, enter rs [nodemon] watching: . [nodemon] starting node ./app module.js:471 throw err; ^

Error: Cannot find module 'connect-mongo' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (/Users/Cynthia/Documents/treehouse/node_authentication_app/app.js:5:42) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:383:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:496:3 [nodemon] app crashed - waiting for file changes before starting...

James Churchill
James Churchill
Treehouse Teacher

Cynthia,

Could you share your project code either in a workspace snapshot or in a GitHub repo?

Thanks ~James

Here is my GitHub link to the app.js file: https://github.com/rockandrollbaby/treehouse.

James Churchill
James Churchill
Treehouse Teacher

Do you have a package.json file?

I added the package.json file: https://github.com/rockandrollbaby/treehouse.

James Churchill
James Churchill
Treehouse Teacher

Great! Now if you run the command npm install (in order to ensure that all of your application's dependencies listed in the package.json file have been installed) and then attempt to run your application using the nodemon command (assuming that you have nodemon installed globally), so you still encounter any errors?

I did the npm install. I ran the nodemon command. The server still won't run. Here are my error messages:

setups-MacBook-Pro:node_authentication_app Cynthia$ nodemon [nodemon] 1.18.9 [nodemon] to restart at any time, enter rs [nodemon] watching: . [nodemon] starting node ./app (node:2198) 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/4.x/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/Cynthia/Documents/treehouse/node_authentication_app/node_modules/mongodb-core/lib/topologies/server.js:336:35) at emitOne (events.js:96:13) at Pool.emit (events.js:188:7) at Connection.<anonymous> (/Users/Cynthia/Documents/treehouse/node_authentication_app/node_modules/mongodb-core/lib/connection/pool.js:280:12) at Connection.g (events.js:292:16) at emitTwo (events.js:106:13) at Connection.emit (events.js:191:7) at Socket.<anonymous> (/Users/Cynthia/Documents/treehouse/node_authentication_app/node_modules/mongodb-core/lib/connection/connection.js:189:49) at Socket.g (events.js:292:16) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at emitErrorNT (net.js:1281:8) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9) name: 'MongoError', message: 'failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]' }

James Churchill
James Churchill
Treehouse Teacher

Do you have the Mongo database daemon running in another command prompt or terminal window? If not, open another command prompt or terminal window and run the command mongod.

It looks like there is a deprecating warning error message: (node:2605) 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/4.x/docs/connections.html#use-mongo-client

I do have those, but my GitHub account didn't let me upload that many folders and files. I will try the app to see if it runs on the server.

Thank you.

It is working! Thank you, James for all of your help!

Hi James,

I am on the Rest API app, and am getting this error message in the terminal:Error: Cannot find module './routes' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (/Users/Cynthia/Documents/treehouse/rest_api_app/app.js:5:14) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) setups-MacBook-Pro:rest_api_app Cynthia$

I did as you said. Does this mean the server is working? ^Csetups-MacBook-Pro:node_authentication_app Cynthia$ nodemon [nodemon] 1.18.9 [nodemon] to restart at any time, enter rs [nodemon] watching: . [nodemon] starting node ./app (node:2605) 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/4.x/docs/connections.html#use-mongo-client Express app listening on port 3000

James Churchill
James Churchill
Treehouse Teacher

Yes, your server is running and listening on port 3000. You're receiving a warning about a method deprecation, but it's just a warning and not an error.

I'm not seeing the public or routes folders in your repo. Do you have those in your project on your machine?