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

来源:互联网 发布:滴定度的浓度算法 编辑:程序博客网 时间:2024/06/05 04:20

刚开始接触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输出一个超级简单的页面