Nodejs/express+mongodb/mongoose__js

Source: Internet
Author: User
Tags install mongodb mongodb install node git clone

Step 1 Install Nodejs

1.1 Install NVM uses NVM (Node Version Manage) Laian to install Node.js,

sudo apt-get install git-core g++ curl

git clone git://github.com/creationix/nvm.git ~/.nvm
echo ". ~/.nvm/nvm.sh ">> ~/.BASHRC

Re-open terminal or enter at current terminal: Source ~/.BASHRC or. ~/.BASHRC reload the BASHRC settings into the current bash environment.

1.2 Install Nodejs
NVM install v0.10.26
NVM alias default v0.10.26

PS:node.js started to build NPM after 0.6.3 (node Package Management),
Use Npm-v for confirmation.

Step 2 Install Express
Express is currently the most popular based on Node.js Web development framework, using it can quickly build a Web site prototype, it is a node.js module, using NPM Global module for installation.
The installation commands are as follows:
NPM Install-g Express

When the installation is complete, create a new project in the working directory, assuming the name Helloword.
Express Helloword

At this point, a Helloword subdirectory is generated in the working directory, as follows:
blwang@blwang-desktop:~/workspace/nodejs_workspace$ Express Helloword


   Create:helloword
   create:helloword/ Package.json
   create:helloword/app.js
   create:helloword/public
   create:helloword/public/javascripts
   create:helloword/public/images
   create:helloword/public/stylesheets
   create:helloword/public/ Stylesheets/style.css
   create:helloword/routes
   create:helloword/routes/index.js
   create:helloword/ Routes/user.js
   create:helloword/views
   create:helloword/views/layout.jade
   create:helloword/views /index.jade

   Install dependencies:
     $ cd helloword && NPM install


   run the app:
     $ node App


As prompted, install dependencies and then run node app to see the generated default Web site framework on local Port 3000.

Access Address: http://127.0.0.1:3000

Step 3 Install MongoDB Installation Reference http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

sudo apt-key adv--keyserver hkp://keyserver.ubuntu.com:80--recv 7f0ceb10
Echo ' Deb http:// Downloads-distro.mongodb.org/repo/ubuntu-upstart Dist 10gen ' | sudo tee/etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install Mongodb-10gen


MongoDB database operations links are as follows: http://docs.mongodb.org/manual/core/crud-introduction/

Step4 Install Mongoose

Many kinds of middleware can be used to connect node.js and MongoDB, and the mongoose is more commonly used.
First, before using the Express new HelloWorld project directory to install Mongoose, the commands are as follows:


NPM Install Mongoose--save

You can then connect the MongoDB database in the Node.js script.
var mongoose = require (' Mongoose ');
Mongoose.connect (' mongodb://localhost/< database name > ');

Note that when you run the above script, you must ensure that the MongoDB is running.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.