Install Node.js on CentOS5.6 (cont.)-Write program validation installation __JS

Source: Internet
Author: User
Tags install mongodb mongodb install node

In the last article, "Installing Node.js on CentOS5.6", the installation was completed 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.

1. Use installation MongoDB drive

# 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

====================================================== ==========================
= = =                                                                              Install with  C + + Bson parser do <npm install MongoDB: native>   = = 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:

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


2. Write test code Mongo.js

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:

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


Reference articles:

Getting Started with VMWare Cloudfoundry, MongoDB and Node.js

Blog rolling with MongoDB, Express and Node.js

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.