[My own finishing] node.js directly outputs a very simple HTML page

Just started to contact nodejs, first record a very simple interface with node output at first

First create a js file helloworld.js on the remote server

[root@towrabbit nodejsLearn]# vi helloworld.js
The content of the file is as follows (you need to press the i key to edit and modify)

console.log('Hello word');
var http = require('http');

http.createServer(function(request,response){
    response.writeHead(200,{'Content-Type':'html'});
    response.write('<!DOCTYPE html>'+
                          '<html>'+
                          '<head>'+
                          '<meta charset="utf-8" />'+
                          '<title>The Rabbit Castle</title>'+
                          '</head>'+
                          '<body>Hahaha my </body>'+
                          '</html>');
              response.end();
}).listen(8888);
console.log('server running at http://xxx.xxx.xxx:8888/');

After editing, enter esc to exit the editing mode and enter: wq to save the document

After that run the helloworld.js file on node

 
 
[root@towrabbit nodejsLearn]# node helloworld.js
Finally output on the server side


output in client browser


node.js outputs a super simple page

Guess you like

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