Install Node.js and MongoDB notes on CentOS

Source: Internet
Author: User
Tags install mongodb json require requires 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://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:

The code is 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:

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

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./install.sh

================================================================================

= =

= 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

Mongodb@0.9.6-23./node_modules/mongodb

Follow the prompts:

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

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, ' 127.0.0.1 ');

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

To start the server:

The code is as follows:

# node Mongo.js

In the browser access http://127.0.0.1:3000, 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

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.