1:配置
下载并安装之后,在cmd直接找到自己需要node运行的文件
d: 回车
代码如下:
这是第一个node执行的代码,结果会在doc黑框上显示console.log的结果。在浏览器上输入http://127.0.0.1:8888 可看到执行结果 hello word!
nodejs自带很多模块,需要我去不断学习。
此段代码中用到的有 1.require("http") //将node中的http模块用require方法取出来并定义给一个叫http的变量,目的是require可返回一个对象,并赋值
使用http中的createServer()方法进行请求和返回值的确定,最后返回的对象由一个listen的方法 进行端口的检测
最后在doc中检测是否跑起来服务
代码:var http = require('http');
http.createServer(function(request,response){
response.writeHead(200,{'Content-Type':'text/plain'});
request.end('Hello Word!');
}).listen(8888);
console.log('http://127.0.0.1:8888');
http://www.runoob.com/nodejs/nodejs-npm.html菜鸟教程