Introduction to Node. js development in Windows (1), windowsnode. js

Source: Internet
Author: User

Introduction to Node. js development in Windows (1), windowsnode. js

It's okay to record Node. js and run Hello World.

Install the Node. js environment in Windows

To the Node official website http://node.org can be downloaded to the installation package, I am Win7 64-bit, visit the Node official website, you can see the latest version is 0.12.7, click INSTALL to download the msi file, double-click to install the SDK.

The installation process is very simple. Select all options and click Next.

Msi will install the npm (Node Package Manager) together and help you set environment variables and add node and npm to the path. Therefore, you only need to open the command line window, you can work now.

A Node. js directory will be added to the Start Menu, as shown in:

Click the "Node. js command prompt" menu to enter the Node. js command line environment, as shown in:

Node and npm can be used directly here.

If you enter node and press enter, you can enter the Node interactive environment. You can enter some JavaScript commands, such as console. log ("Hello Node. js !"), There is a reaction. Enter the node effect, which is equivalent to clicking the Node. js menu in the Start Menu.

If you enter npm and press enter, you will see npm help, for example:

The basic environment is just like this. It's very simple. Next we will start to look at HelloWorld.

HelloWorld website

The code is so simple:

// Introduce the http module var http = require ("http"); // create a server and specify the function http to process client requests. createServer (function (request, response) {response. writeHead (200, {"Content-Type": "text/plain"}); response. write ("Hello World! "); Response. end () ;}). listen (8000); console. log (" Hello World is listening at port 8000 ");

Save as HelloWorld. js. In the Node. js command line environment, enter the directory of HelloWorld. js and execute node HelloWorld. js to run the website.

In our simple example, "Hello World!" is returned for any request !" Text string, you can enter "http: // localhost: 8000" in the browser to see the effect. Here I am in soy sauce:

Nothing special, ugly, right. For more information about what the http module is, see http://nodejs.org/dist/v0.12.7/docs/api/http.html.

That's how the magic world started ...... The Start menu contains the Node. js documentation sub-menu, which can be directly connected to the Node. js online documentation. More highlights can be started from there.

Next time, let's see how to install Express and use it to write a HelloWorld website. Let's see what is different from here.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.