Nodejs新手入门以及简单的web案例

我用的是Window系统,其他系统应该也差不多吧

1、下载

https://nodejs.org/en/

直接点击最新版本下载就好了

2、安装

3、测试

打开cmd命令行,直接输入 node 然后回车

键入 console.log("Hello,World!");

查看输出结果

Hello,World!
undefined

4、创建工作目录

随便找个系统盘,创建workspace\nodejs\

5、创建简单的web项目

创建httpdemo/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.end("<p>Game Over hhhhh</p>");
}).listen(8089);
console.log("HTTP server is listening at port 8089.");

然后启动:

cmd转到文件目录输入:node test.js

回车

然后在浏览器中输入:http://localhost:8089/

如果能看到输出结果,则表明成功。

 

posted @ 2015-11-25 13:01  DarkArts  阅读(267)  评论(0)    收藏  举报