【自己的整理】node.js直接输出一个非常简单的HTML页面

刚开始接触nodejs,先记录一下最开始用node输出一个很简单的界面

在远程服务器上先创建一个js文件 helloworld.js

[root@towrabbit nodejsLearn]# vi helloworld.js
文件内容如下(需要通过按i键来进行编辑修改)

console.log('哈罗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>兔子城堡</title>'+
                          '</head>'+
                          '<body>哈哈哈啰我的</body>'+
                          '</html>');
              response.end();
}).listen(8888);
console.log('server running at http://xxx.xxx.xxx:8888/');

编辑完毕之后输入esc推出编辑模式并输入:wq来保存文档

之后在node上运行helloworld.js文件

 
 
[root@towrabbit nodejsLearn]# node helloworld.js
最后在服务器端输出


在客户端浏览器输出


node.js输出一个超级简单的页面

猜你喜欢

转载自blog.csdn.net/towrabbit/article/details/78344975
今日推荐