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 ....