【Node.js】 First experience

1. Create a new app.js file

2. Use npm install http to import the http module

3. Go directly to the code

// Introduce http module 
var http = require('http' );
 // Create server 
var app=http.createServer( function (request, response) {

    // Send HTTP header 
    // HTTP status value: 200 : OK 
    // Content type: text/plain 
    response.writeHead(200, {'Content-Type': 'text/plain' });

    // Send response data "Hello Node.js" 
    response.end('Hello Node.js' );

}) 
//Add listener, listen on port 3000 app.listen(
'3000',()=>{console.info("The server was created successfully, port number: 3000")})

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325297749&siteId=291194637