NodeJs development (1)

Source: Internet
Author: User

Step 1: Download the Installation File

: Official http://www.nodejs.org/download/

<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + CtXiwO/tw7xeyscgpgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140402/20140402085924174.jpg" alt = "\">

Step 2: Install nodejs

After the download is complete, double-click the node-v0.8.16-x86.msi, start to install nodejs, the default is installed in C: \ Program Files \ nodejs below

Step 3: Install related environments

Open the C: \ Program Files \ nodejs directory and you will find that npm is included in it. You can directly use npm to install the environment

Enter the node. js command prompt command window

Go to the nodejs installation directory C: \ Program Files \ nodejs

Run the following command: cd C: \ Program Files \ nodejs:

Now start to install the relevant environment

Enter the command: npm express and press enter to wait for the installation of express ........

Enter the command: npm jade and press enter to wait for jade installation ........

Enter the command: npm mysql and press enter to wait for mysql installation ........

What components are installed depends on the environment construction requirements

By default, the above components are installed in the C: \ Program Files \ nodejs \ node_modules folder, which is also the automatic search path for node. js-related components.

Step 4: Create a project

Now there is express

The express command takes effect only when it is installed globally!

Therefore, when installing express, use npm install express-g

Or directly modify the Global Path:

Npm config set prefix "C: \ Program Files \ nodejs"

Npm config set cache "C: \ Program Files \ nodejs \ cache" (create the cache directory first)

Type: express myapp (myapp is a random project name)

You will find an additional C: \ Program Files \ nodejs \ myapp directory

By default

I don't want to explain these files. I believe that anyone with development experience can understand them at a glance.

Copy node_modules to myapp

After the environment is set up, we will perform a demo test!

Create helloworld. js under myapp

var http = require("http");http.createServer(function(request, response) {      response.writeHead(200, {"Content-Type": "text/plain"});      response.write("Hello World");      response.end();}).listen(8888);console.log("nodejs start listen 8888 port!");

Go to the node. js command prompt command window and enter the C: \ Program Files \ nodejs \ myapp directory.

Type node helloworld. js

Http: // 127.0.0.1: 8888/

Output:

Hello World

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