Install Node.js and MongoDB notes on CentOS _node.js

Source: Internet
Author: User
Tags install mongodb mongodb install node using git joyent

I've heard of Node.js before, but I know it can be applied to the server, but I don't know a lot of specific things. Today in Qcon listened to Shong share "node.js out of the browser JavaScript," Immediately after the impulse to try immediately.

Node.js installation steps are relatively simple, not too many detours, the main reference documents:

Building and installing Node.js

1. Install Python

According to the reference documentation, compiling the installation node.js from the source code requires python2.6 or more, while the Yum install python.x86_64 can only get 2.4.3, so you also need to compile and install Python via source. Here's the command:

Copy Code code as follows:

# wget Http://www.python.org/ftp/python/3.2.2/Python-3.2.2.tgz
# tar XZVF python-3.2.3.tgz
# CD Python-3.2.2
#./configure
# make
# Make Test
# make Install

After the installation is complete, execute the python command and go to the Python Command line window.

2. Install Node.js

Follow the instructions on the document to never succeed with git checkout code, whether using Git://github.com/joyent/node.git or https://github.com/joyent/node.git. So you can only download and then compile the installation from the GitHub network, the following steps are specified:

Copy Code code as follows:

# wget Https://nodeload.github.com/joyent/node/tarball/master
# MV Master node.tar.gz
# tar XZVF node.tar.gz
# CD Joyent-node-84d0b1b
#./configure--prefix=/opt/node/
# make
# make Install
# Cd/usr/bin
# Ln-s/opt/node/bin/node Node
# ln-s/opt/node/bin/node-waf Node-waf

3. Install NPM

NPM is the package manager used to install the Node.js library, and the installation commands are fairly straightforward:

Copy Code code as follows:

# Curl Http://npmjs.org/install.sh | Sh

At this point, the installation is complete.

In the above section, the installation is done in a few simple steps. Although it looks like the installation was successful, it actually requires us to write a program to verify it. Since I've been learning MongoDB recently, I'm writing a read MongoDB database: Calculates the total number of logs that ActionId is 772.

4. Use Installation MongoDB Drive

Copy Code code as follows:

# NPM Install MongoDB
NPM WARN mongodb@0.9.6-23 package.json:bugs[' web ' should probably be bugs[' url '
NPM WARN nodeunit@0.5.1 package.json:bugs[' web ' should probably be bugs[' url '

> mongodb@0.9.6-23 Install/root/develop/node/node_modules/mongodb
> Bash./install.sh

================================================================================
=                                                                              =
= To install with C + + Bson parser do <npm Install MongoDB =
= The parser only works for node 0.4.X or lower =
=                                                                              =
================================================================================
Not building native library for Cygwin
Using GNU Make
Mongodb@0.9.6-23./node_modules/mongodb

Follow the prompts:

Copy Code code as follows:

# CD Node_modules/mongodb
# bash./install.sh

Note: The driver must be installed in the same directory as the project, not all items will be installed once.

5. Write test Code Mongo.js

Copy Code code as follows:

var http = require (' http ');
var MongoDB = require (' MongoDB ');

Http.createserver (function (req, res) {
Res.writehead ({' Content-type ': ' Text/plain;charset=utf-8 '});
Mongodb.connect (' Mongodb://localhost:40202/log ', function (err, conn) {
Conn.collection (' Log ', function (err, coll) {
Coll.count ({' Action ': 772}, Function (err, count) {
Res.write (' The total of action 772 ' + Count + '. \ n ');
Res.end ();
});
});
});
}). Listen (3000, ' 127.0.0.1 ');

Console.log (' Server running at Http://127.0.0.1:3000/');

To start the server:
Copy Code code as follows:

# node Mongo.js

In the browser access http://127.0.0.1:3000, you can see the following output:

Now it can be said that the previous installation process is correct and open a good head.

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.