您的位置:首页 > Web前端 > Node.js

node.js-<一>安装运行第一个程序

2014-11-24 11:32 573 查看
1>windows版本

从官网下载node.js的windows的安装文件进行安装;

2>编写js文件 test.js假设文件都在D盘根目录下

1)在控制台打印程序

console.log("hello world");

2)创建Server,编写server.js
var http = require('http');

http.createServer(function(req,res)
{
res.writeHead(200,{'Content-Type':'text/html'});
res.write('<h1>Node.js</h1>');
res.end('<p>hello world</p>');
}).listen(3000);
console.log("port:3000");

3>运行js文件
开始菜单找到Node.js command prompt快捷方式

运行如下:

d:

node

cd ..

node test.js

同样的方式运行server.js

4>查看server.js运行结果

浏览器输入 http://127.0.0.1:3000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  node.js