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