Nodejs installation and Running Experience

Source: Internet
Author: User

Refer to official website: http://nodejs.org/

1. Building and installing node. jsstep 1-Pick your platform

Node shoshould install out of the box on Linux, Macintosh, and Solaris.

With some effort you shoshould be able to get it running on other UNIX
Platforms and windows (either via cygwin or mingw ).

Step 2-prerequisites

Node has several dependencies, but fortunately most of them are
Distributed along with it. If you are building from source you shoshould
Only need 2 things.

  • Python-Version 2.4 or higher. The build tools distributed
    Node run on python.

  • Libssl-Dev-If you plan to use SSL/TLS encryption in your
    Networking, you'll need this. libssl is the library used in
    OpenSSL tool. on Linux and UNIX systems
    It can be usually be installed with your favorite Package Manager.
    Lib comes pre-installed on OS X.

Step 3A-installing on Unix (including BSD and Mac)

Building from source

Use make to build and install node (execute the following on the command line)

git clone --depth 1 https://github.com/joyent/node.gitcd nodeexport JOBS=2 # optional, sets number of parallel commands.mkdir ~/local./configure --prefix=$HOME/local/nodemakemake installexport PATH=$HOME/local/node/bin:$PATH

If you have any installation problems, look at troubleshooting
Installation, try an alternate installation method, or stop into # Node. js and ask questions.

Pre-built Binaries

You can also install node from packages: Installing node. js via Package Manager

Step 3b-building on Windows

Pre-built Binaries

Self-contained binaries are available at node-js.prcn.co.cc

Building from source

There are two ways of building node on Windows. One is over the cygwin
Emulation layer the other is using mingw (GNU toolchain
Windows). See
Cygwin
And mingw
Pages.

Neither builds are satisfactorily stable but it is possible to get
Something running.

Step 4-install NPM

NPM is a package manager that has become the de-facto standard
Installing additional node libraries and programs. Here's the quick
And easy one-liner for installing on UNIX.

# curl http://npmjs.org/install.sh | sh

To install a library e.g. Express:

# npm install express

And visit
Https://github.com/isaacs/npm
Details.

2. How to Run node. js

An example of a Web server written in node which responds
"Hello World" for every request.

var http = require('http');http.createServer(function (req, res) {  res.writeHead(200, {'Content-Type': 'text/plain'});  res.end('Hello World\n');}).listen(1337, "127.0.0.1");console.log('Server running at http://127.0.0.1:1337/');

To run the server, put the codeA file helloworld.jsAnd execute it withnode
Program:

Node helloworld. js

Then request http: // 127.0.0.1: 1337 in browser, the page will showHello World


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.