1. Install: You can download all versions of Nodejs in http://nodejs.org/dist/, I downloaded the node-v8.9.0-x64.msi in it, the installation is complete, at the command prompt, enter "node--version" to detect whether the installation is successful.
2.node.js Create the first app:
Create a new file named Server.js in the D drive with the following code:
var http = require (' http '); Http.createserver (function (request, response) { //Send HTTP Header //HTTP status value: 200:ok
//content Type: Text/plain response.writehead ($, {' Content-type ': ' Text/plain '}); Send the response data "Hello World" response.end (' Hello world\n ');}). Listen (8888);//terminal print the following information Console.log (' Server running at http://127.0.0.1:8888/')
Enter "Node Server.js" to execute the above code with the following results:
3.NPM:NPM is a package management tool that is installed with Nodejs and tests whether NPM was successfully installed by entering "npm-v".
4. Install the module using the NPM command:
The above error occurs because the directory is not installed, modified, the following is a global installation, so you need to configure environment variables:
5.nodejs callback function:
Create the Main.js file with the following code:
var fs = require ("FS"); var data = Fs.readfilesync (' input.txt '); Console.log (data.tostring ()); Console.log ("program execution ends!");
Create the TXT file and Main.js file to ensure that the encoding method is UTF-8, in terms of TXT file, save to pay attention to its encoding.
Nodejs Learning (1)