Nodejs+express4.0+mongodb installation method for Linux, Mac

Source: Internet
Author: User
Tags mongodb server nginx server

No more nonsense.

1: Download the Nodejs package

as follows: http://www.nodejs.org/download/

Download source code version needs to be extracted to its directory execution./configure, then make && make install;

and binaries tar.gz after decompression can.


2: Download MongoDB

as follows: Http://www.mongodb.org/downloads

and binaries tar.gz after decompression can.


3: Configure Environment variables

CD ~; This directory has a. Bash_profile edit it

Export node_home= $HOME/(Node_path); export mongodb_home= $HOME/(mongodb_path); Export PATH = $PATH: $NODE _home/bin:$ Mongodb_home/bin;export node_path= $NODE _home/lib/node_modules: $PATH;

(node_path) node unzipped directory, (mongodb_path) MongoDB unzipped directory

Then execute node-v,npm-v and mongo-version to determine if the configuration environment is successful. Success will see the version number.

4: Install express4.x


And then execute
Express Ejs NodeTest
Go to nodetest directory execution

NPM INSTALLNPM Start

This launches a service

You can access the http://127.0.0.1:3000 in this server's browser


5:mongodb Server

Start the MongoDB server first

Mongod--dbpath= (Mongodb_path)/db

(Mongodb_path) you want to store the DB directory, as long as you have access to any place.

After execution, you can execute the database operation with a command by executing MONGO.

Specific Nodejs access to MONGODB operations.

var Mongodb = require ("MongoDB"),      Db = mongodb.db,      Connection = mongodb.connection,      Server = Mongodb.server var mongo = new Db ("TestDb", New Server ("localhost", connection.default_port), {safe:true}), Mongo.open (function (Err, db) {   db.collection ("test_table", function (err,collection) {      collection.save ({name: ' Test '},{safe:true}, function (Err,app) {         mongo.close ();         Console.log (app);});})

Finally configure the domain name of Nodejs

Otherwise, it's always ip:port access too cumbersome.

An example of Nginx server

Just configure the vhost below it to create a domain name you name can be

Example: vhost/sys.test.com.conf

server{   Listen;   server_name sys.test.com.conf;   Location/{      proxy_pass http://127.0.0.1:3000;   }}

Ok. Rest ..... Take a break ....








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.