远行的心 发表于 2017-2-21 10:10:37

Windows下安装nodejs

  我的博客地址:wwww.tangwen.org ,更多不断更新。


window下安装包 官网http://nodejs.org/

node-v0.6.12.msi  安装即可,通过cmd 命令进入,再打node ..命令执行成功。

默认安装路径为C:\Program Files\nodejs

小试牛刀:
  index.js

/**
第一节:开篇章
*小试牛刀
**/
//创建http对象
var http = require('http');
//创建服务端
http.createServer(function (request, response) {
//发送一个HTTP状态200和HTTP头的内容类型(content-type),
response.writeHead(200, {'Content-Type': 'text/plain'});
//向HTTP相应主体中发送文本,完成响应
response.end('Hello World\n');
//输出日志信息
console.log('Server running function');
}).listen(8888);
//输出日志信息
console.log('Server running at http://127.0.0.1:8888/');

/*
第二种方法:
以下方法等同于上面方法
var http = require('http');
function onRequest(request, response){
response.writeHead(200,{'Content-Type':'text/plain'});
response.end('Hello World\n');
console.log('Server running function onSer');
}
http.createServer(onRequest).listen('8888');
console.log('Server running at http://127.0.0.1:8888/');
*/

  执行cmd命令,再执行 node d:\index.js 即可,执行后出现:


Server running at http://127.0.0.1:8888/
 






1

Server running at http://127.0.0.1:8888/






  即可通过浏览器访问,访问地址:http://127.0.0.1:8888/
页: [1]
查看完整版本: Windows下安装nodejs