zoukankan      html  css  js  c++  java
  • NodeJS安装运行体验 Anny

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

    1. Building and Installing Node.js

    Step 1 - Pick Your Platform

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

    With some effort you should 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 should only need 2 things.

    • python - version 2.4 or higher. The build tools distributed with 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 the openssl tool. On Linux and Unix systems it can usually be installed with your favorite package manager. The 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.git
    cd node
    export JOBS=2 # optional, sets number of parallel commands.
    mkdir ~/local
    ./configure --prefix=$HOME/local/node
    make
    make install
    export 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 for windows). See the 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 for 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 for details.

    2. How to run Node.js

    An example of a web server written in Node which responds with "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 code into a file helloworld.js and execute it with the node program:

    node helloworld.js

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

     
  • 相关阅读:
    HDU 1863 畅通工程(并查集)
    HDU 1232 畅通工程
    洛谷 1162 填涂颜色 (dfs,染色法)
    HDU 2689 sort it(树状数组 逆序数)
    mod_js.so下载 转自网络
    The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
    B计划 第七周
    B计划 第六周
    B计划 第五周
    B计划 第四周(开学第一周)
  • 原文地址:https://www.cnblogs.com/limei/p/2060119.html
Copyright © 2011-2022 走看看