windows下安装NodeJs

1.官网(//nodejs.org/en/)下载系统匹配的文件

2.双击安装,完成后发现nodejs文件夹下面有npm, 直接用npm安装其他环境既可

3.如果配置了环境变量,直接Win+R后CMD调出DOS窗口输入node,即可进入nodejs交互模式
测试:console.log("Hello World!");

4.任意目录下建个app文件夹,创建test.js,代码如下:

var http = require("http");

http.createServer(function(req, res) {

res.writeHead(200, {"Content-Type":"text/html"});
res.write("<h1>Node.js</h1>");
res.write("<p>Hello World</p>");
res.end("<p>cn.cn</p>");

}).listen(3000);

console.log("HTTP server is listening at port 3000.");

 

5.DOS窗口进入app文件夹,在命令窗口执行node test, 启动服务端。接着浏览器访问:http://127.0.0.1:3000

posted @ 2016-07-28 11:01  再見理想  阅读(160)  评论(0编辑  收藏  举报