Christopher, you are the man! Thank you!
Note to moderators, Conrad Pankoff bills himself as a "Professional Cyber Bully" : http://webcache.googleusercontent.com/search?q=cache:GvjFQCWny-AJ:about.me/deoxxa+&cd=12&hl=en&ct=clnk&gl=us On Wed, Apr 9, 2014 at 12:31 AM, Christopher Mina < christopher.m...@gmail.com> wrote: > Frank, > > All the other crap aside, hopefully by now you have figured out the > issue. However, I'll try to be a little more crystal clear than what has > been posted already. > > You've got a couple issues, starting at the beginning: > > 1) You're correct, mongod process is already running, so you're good > there. > 2) It sounds like you may have copy / pasted code from an Express.js > tutorial. A good first place would always be to fully understand what is > going on with every line of code when running through a tutorial. Usually > there is a line-by-line guide or some sort of documentation to walk you > through it. > 3) You're Express app configuration file is fine, as you said, you ran npm > install against package.json and all worked well. Good. > 4) Now we come to the meat of the problem, when the express app is > starting, it does a bunch of things defined in app.js, including setting up > your Express routes. This is line that reads: "app.get('/users', > user.list);" What this says is "When user navigates to > http://{myapp.com}/users, > invoke the function "list" on the object "user". User.list (function) is > your callback to that URL route. > > In Node, as in javascript in general and any other language, you must > define something before invoking it. I'm sure you understand this part > perfectly well. However, assuming you read the error carefully, you'll > notice it says: "ReferenceError: user is not defined". This should look > identical to errors you have seen in client side code before. What it says > is that you are attempting to reference an object (user) that does not > exist. Without seeing your code, its difficult to determine why this > doesn't exist. However, there are some very common things to know about > Node, one of which is how to "include" another JS file. Assuming you had > another file named "User.js", and within that was a "class" function or > object literal, and within that was a method called "list", then you would > reference that with as: > > var user = require("path/to/models/User.js"); > > So long as this was done above the declaration of the route, it would all > work. Another option would be if the "user" was declared inline. For > instance, it might look like: > > var user = function() { > }; > > user.list = function() { > }; > > Or better yet, "list" would be applied to the prototype: > user.prototype.list = function() { }; > > Any of these cases, so long as they are defined or referenced above the > ("/users", user.list), would cause your app to run. > > > Regarding Mongoose, it is absolutely not required. You can use the native > Javascript driver for mongodb just fine ( > http://docs.mongodb.org/ecosystem/drivers/javascript/), or any of several > other libraries (e.g. Mongoskin). However, it seems like your tutorial is > using mongoose, as it simplifies things just to get started. So you should > stick with that. > > Regarding Mongodb in general, hopefully by now it is clear that your null > reference error has nothing to do with Mongo or its setup. > > > > On Tuesday, April 8, 2014 6:10:27 PM UTC-6, Frank Z wrote: >> >> I installed mongodb through my unbuntu terminal after installing node.js. >> >> When I run sudo service mongodb start >> >> I get back "start: Job is already running: mongodb" from the terminal >> >> So my assumption is that everything is running properly here... >> >> I'm trying to make this todo list from an example in my book, using >> express.js. I used the package.json file to install the depenencies: >> >> { >> "name": "application-name", >> "version": "0.0.1", >> "private": true, >> "scripts": { >> "start": "node app.js" >> }, >> "dependencies": { >> "express": "3.5.1", >> "jade": "*", >> "mongoose":"3.8.4" >> } >> } >> >> Then I run npm install in my terminal... >> >> Everything is correct in my app.js file, all the variables declared >> properly with mongoose and everything... >> >> I run node app.js and get back: >> >> /home/frankz/Desktop/nodesandbox/connect_to_mongo/app.js:40 >> app.get('/users', user.list); >> ^ >> ReferenceError: user is not defined >> at Object.<anonymous> (/home/frankz/Desktop/ >> nodesandbox/connect_to_mongo/app.js:40:19) >> at Module._compile (module.js:456:26) >> at Object.Module._extensions..js (module.js:474:10) >> at Module.load (module.js:356:32) >> at Function.Module._load (module.js:312:12) >> at Function.Module.runMain (module.js:497:10) >> at startup (node.js:119:16) >> at node.js:902:3 >> >> So what's going on here? >> > -- > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com > To unsubscribe from this group, send email to > nodejs+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > > --- > You received this message because you are subscribed to a topic in the > Google Groups "nodejs" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/nodejs/XF9mhLAGepQ/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > nodejs+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.