node. js Getting Started Tutorial (a): Preparing

Source: Internet
Author: User

Because the new job to do front-end, as the front-end small white and can learn as soon as possible, so choose the web of node. JS's Introductory tutorial. Blogs only do their own records of learning.

node. JS is essentially a JavaScript runtime environment. You can parse the JS code (without the restrictions of the browser security level) and provide the system-level API:

1. file reading and writing

2. Management of processes

3. Communication of the network

I. Installing node. JS (0.10.3x)

Install MSI on WIN10 and encounter permissions problems, the workaround is as follows:

1, the mouse moved to the lower left corner of the desktop (or directly: win+x key), command Prompt (administrator);
2. Input:msiexec/package + ' msi file path '(note the half-width character when input and the path cannot be Chinese name)
For example:
c:\windows\system32>msiexec/package G:\tool\TortoiseSVN-x64-1.8.9.msi

Installation is successful and the version number is displayed in CMD run node-v

Two. node. JS trial Run

Use the official example:

var http = require (' http ');
Http.createserver (function (req,res) {
Res.writehead ($, {' 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 ');

CMD start node server.js

Code parsing:

var http = require (' http '); ---> Load HTTP module, the responsibility is to create a Web server, and handle HTTP-related tasks, etc.

listen (1337, ' 127.0.0.1 '); --->listen allow the server to listen on port 1337

http.createserver (req,res) {--->createserver a Web server was created and passed in an anonymous callback function that is invoked once the listen has been requested. , the anonymous function has two parameters, req the request body, res response body.

req used to obtain request-related information, such as URL, request type, etc.

res used to tell the server what the response to this request

res.writehead ($, {' Content-type ': ' Text/plain '}); ---> The header of the response body, including the status code, response content type

node. js Getting Started Tutorial (a): Preparing

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.