The Dead-simple step-by-step GUIDE for front-end developers to getting up and RUNNING with NODE. JS, Express,jade and MONGODB
Translated from: http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/
An introduction
There are approximately one hundred million tutorials on the web for getting a "Hello, world!" app running with Node.js. There are hundreds of millions of Nodejs running "Hello World" apps available online. This is great if your goal is to stop at the hello level and give up your web career.
That's doesn ' t really describe most of us, so we go looking for more tutorials. Of course that doesn't mean most of us, so we'll look for more tutorials.
In my experience, the ' next level ' tutorials out there seem about levels further. According to my experience, the "Next level" tutorial seems to have 30 levels to go. From the application of Hello world to the creation of the entire blog with comments function.
1 part1:15 MINUTES of installing 15-minute installation
I run under the WIN8 system, so it's a little bit different from those Mac or Ubuntu or *nix systems, but the basics are the same.
A: The 1th step to install Node.js is very simple, visit the Node.js website website, click the Big Green Installation button. It installs the corresponding application according to your OS installation. Running installer, after installing Node.js, NPM (Node Package Manager), it is very important to quickly and easily add a variety of stuff to the Node machine.
Open the Command Window CD to create a directory that holds the path to the test application you want. (The test application directory for this article is: C:\node) B: 2nd step: Installation of Express
Now that our node is running, we need other tools when we create an available Web site. We're going to install Express, Express is a framework that transforms simple nodejs into more like a Web server that we've used.
C:\NODE>NPM Install-g Express
This installs some core Express functionality to our Node installation, making it available globally so we can use It anywhere we want. That ' s handy. You ll have a bunch of the text in your command prompt, mostly a lot of HTTP 304 ' s and GETs. That ' s fine. The Express is now installed and available.
This allows you to install some of the core features of Express, G is to make it a global win, so we can apply anywhere, that is very convenient. You will see a series of text in your command window, most of which are HTTP requests or get requests, very good, now the Express has been installed successfully and available.
C: 3rd step: Create a Express project
C:\node>express--sessions Nodetest1
Click Enter and you will see the following:
C:\node>express--sessions nodetest1
create:nodetest1
create:nodetest1/package.json
Create: Nodetest1/app.js
create:nodetest1/routes
create:nodetest1/routes/index.js
create:nodetest1/routes/ User.js
create:nodetest1/views
create:nodetest1/views/layout.jade
create:nodetest1/views/ Index.jade
create:nodetest1/public/images
create:nodetest1/public/javascripts
create:nodetest1/ Public
create:nodetest1/public/stylesheets
create:nodetest1/public/stylesheets/style.css
Install dependencies:
$ cd nodetest1 && NPM install
run the app:
$ node App
D: 4th step: Edit Dependencies
OK, now we have some basic structure in there, but we ' re not quite done. You'll note this express installation routine created a file called Package.json in your directory. Open this up in a-text editor and it ' ll look like this:
{
' name ': ' Application-name ', '
version ': ' 0.0.1 ',
' private ': true,
' scripts ': {
' start ': ' Node App.js "
},
" dependencies ": {
" Express ":" 3.3.6 ",
" Jade ":" * "
}
}
This is the basic JSON file describing our application and its dependencies. We need to add some content. In particular, we need to introduce MongoDB and monk, let's add the following dependencies:
"Dependencies": {
"Express": "3.3.6",
"Ejs": "*",
"MongoDB": "1.3.19",
"Monk": "0.7.1"
}
E: Installation dependencies
Now we ' re ready. Note, that those version numbers might is out of date by the time you read this article. Can check them from your command prompt with "NPM info [Dependency] Version" (EG:NPM info MongoDB version). Return to your command prompt, CD to your Nodetest1 directory, and type this:
Now we go on. Note that these version numbers may be out of date when you read this article. You will now detect them from your command window (NPM into[dependency] version). Return to your command window, create the Nodetest1 directory, and enter the following information:
C:\NODE\NODETEST1>NPM Install
It ' s going to print out a ton of stuff. That ' s because it's reading the JSON file we just edited and installing all the stuff listed in the Dependencies object (Y ES, including express–we installed, stuff using THE–G flag, but we still have to install some necessary co De for this particular project). Once NPM has run its course, your should have a node_modules directory which contains all to our we dependencies for this Tuto Rial.
Once you run NPM, a node_modules directory will be generated to include all of our dependencies in the article.
Now that we have a fully operational application, let's test it. Directory go to your Nodetest1 directory, enter
C:\node\nodetest1>node App.js
Express Server listening on port 3000
Open the browser input http://localhost:3000 you will see the Express Welcome page.