node.js 笔记一

时间:2023-05-12 22:53:02

现在地址:http://nodejs.org/download/

我的机器是windows的,选择的文件是,是编译后的版本:Windows Installer (.msi)  32-bit

example

打开你最喜欢的编辑器,创建一个helloworld.js文件,输入console.log("Hello World");后保存

打开Node.js的CMD窗口,将文件拖拽到窗口中,输入node js文件路径

Http版例子

编写 q.js 代码如下:

  1. var http = require('http');
  2. server = http.createServer(function (req, res) {
  3. res.writeHeader(200, {"Content-Type": "text/plain"});
  4. res.end("Hello World\n");
  5. })
  6. server.listen(8000);
  7. console.log("httpd start @8000");

运行 node q.js按照上面node.js cmd的方法,控制台显示 httpd start @8000 
打开浏览器访问 http://localhost:8000/ 浏览器显示 Hello World

node.js 笔记一