1. Install node locally

Node is a Web engine based on JavaScript of V8 engine. The HTTP module of Node is needed to build HTTP request and response services

2. Create an http.js file in a directory (any directory)

This http.js file is the HTTP server, and you can customize the listening port, but the IP address must be native.

Var HTTP = require(' HTTP '); Var server = http.createserver () Server. on('request', function (request, response) {// The request object contains: // We can obtain the data submitted by the user through the request object // Response object, which is used to respond some data // When the server wants to respond to the data to the client, it must use the response object // response HTML code, Responsetheader (' content-type ', 'text/ HTML; charset=utf-8'); Response.write ('Hello, My Love') response.end()}) //3. Listen (9099, '192.168.1.112') // server.listen(8201, 'http://192.168.1.116') // Not the local address failed //4. Log (' 3030 executed ') console.log(' 8201 executed ')Copy the code

3. Open the DOS window to switch to the http.js directory and run the following command:

node http.js
Copy the code

Then in the DOSC window you can see the output ‘Execution 3030’

4. Open the browser and enter 192.168.1.112:9099

You can see the following page:

In fact, all individual JS files (which are not imported into HTML files) can be run directly in the corresponding directory using Node. Node also acts as a JS compiler and virtual machine (similar to a JVM) here