Install Node.js and MongoDB notes on CentOS

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

install Node.js and MongoDB notes on CentOS

This article mainly introduces the installation of Node.js and MongoDB notes on CentOS, this article explains the Python installation, node.js installation, NPM installation, MongoDB driver installation, MONGODB database operation test code and so on, the need for friends can refer to the following

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:

The code is as follows:

# wget Http://

# tar XZVF python-3.2.3.tgz

# CD Python-3.2.2


# 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:// or So you can only download and then compile the installation from the GitHub network, the following steps are specified:

The code is as follows:

# wget Https://

# MV Master node.tar.gz

# tar XZVF node.tar.gz

# CD Joyent-node-84d0b1b


# 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:

The code is as follows:

# Curl Http:// | 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

The code is 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./


= =

= To install with C + + Bson parser do =

= The parser only works for node 0.4.X or lower =

= =


Not building native library for Cygwin

Using GNU Make


Follow the prompts:

The code is as follows:

# CD Node_modules/mongodb

# bash./

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

The code is 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 is ' + count + '. N ');

Res.end ();




}). Listen (3000, ' ');

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

To start the server:

The code is as follows:

# node Mongo.js

In the browser access, you can see the following output:

Now you can say that the previous installation process is correct and has a good head start.

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