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

我用的是Window系统,其余系统应该也差很少吧html

一、下载node

https://nodejs.org/en/web

直接点击最新版本下载就行了浏览器

二、安装测试

三、测试ui

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

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

查看输出结果code

Hello,World!
undefined

四、建立工做目录server

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

五、建立简单的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/

若是能看到输出结果,则代表成功。

相关文章
相关标签/搜索