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 Build a REST API With Express Modeling Data for the API Connecting Mongoose to MongoDB

trying to connect Mongoose to Mongodb

This is my error message in the terminal:setups-MacBook-Pro:rest_api_app Cynthia$ node mongoose_sandbox.js /Users/Cynthia/Documents/treehouse/rest_api_app/mongoose_sandbox.js:11 }); ^

SyntaxError: Unexpected token ) at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) 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) setups-MacBook-Pro:rest_api_app Cynthia$ node mongoose_sandbox.js connection error: { Error: connect ECONNREFUSED 127.0.0.1:27017 at Object.exports._errnoException (util.js:1020:11) at exports._exceptionWithHostPort (util.js:1043:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14) name: 'MongoError', message: 'connect ECONNREFUSED 127.0.0.1:27017' } setups-MacBook-Pro:rest_api_app Cynthia$

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

FYI it seems like there's a syntax error. The error shows up in the error as being on line 56 of vm.js. But it seems like this is a error message related to some sort of build process or windows virtual machine.

At any rate, the syntax error is probably in your code, not actually in vm.js. I suggest running your code through a tool like JSHint where you can often get more meaningful hints and error messages.

1 Answer

Here is the link to my GitHub files: https://github.com/rockandrollbaby/rest_api_app.

I went into JSHint and it says that require is not defined. But, I defined it in this statement.: var mongoose = require("mongoose");