Learn to build a small website _5_ start _helloworld and development environment and APIs

Source: Internet
Author: User
Tags install node

    • Hello World

Under the Blogwebsite directory:

Create a new helloworld.js with the following code:

var http = require (' http '); http.createserver(function(req, res) {    Res.writehead ( 200,{' content-type ': ' Text/plain '});    Res.end (' Hello blogwebsite!\n ');    }). Listen (9999, ' 127.0.0.1 '); Console.log ("Hello Blogwebsite started");

CMD, enter the Blogwebsite directory,

Node Helloworld.js

Then open the browser and access http://127.0.0.1:9999/

See Hello blogwebsite!  that represents success.
    • Development Environment VSC

Based on the high (TOU) efficiency (LAN) principle, you need a development tool that works better than a text editor, primarily to have keyword coloring and code hints

VSC is chosen here, and the others are sublime,atom, etc.

Https://www.visualstudio.com/en-us/products/code-vs.aspx

Fool-Type Installation

After installation, open, File->open Folder, navigate to Blogwebsite Open

Almost like this.

Open, Helloworld.js, basic code coloring highlights are available, but the code hints or something is not or very weak, such as the Createserver method can not be automatically prompted

Code hints, need to install another thing, TSD

Back to CMD, enter the Blogwebsite directory, global installation TSD (about typescript knowledge, you can Baidu or here to see http://www.typescriptlang.org/)

NPM install-g TSD

After installing the TS file of the module involved via TSD, the node is used here

TSD Install node--save

After successful execution, the Blogwebsite directory will have more Typings folders and Tsd.json

Typings folder, storing *.d.ts files

Tsd.json, log the TS file used (you need to specify the--save parameter at installation)

Back to VSC, now http. and Createserver have a message.

Official documentation in this: https://nodejs.org/api/

Look back at the code, simplified as follows:

1 var // introducing an HTTP package 2 3 // invoke the Createserver method in the HTTP package 4 5 function // Write specific business logic in the callback function (callback) function 6     7 ). Listen (9999, ' 127.0.0.1 '); // listening to host and Port

What does Createserver do? Query node Official document Https://nodejs.org/api/http.html#http_http_createserver_requestlistener

Just three lines, no sense of consciousness. ~ ~ ~

So leave two pits, tell.

1. How do I know what parameters createserver need to pass?

2. What is a callback function?

Learn to build a small website _5_ start _helloworld and development environment and APIs

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.