NodeJs学习(一)

第一步,大家都知道的,肯定下载安装包,下载地址:http://nodejs.org/

下载完成后直接安装,安装成功后,打开cmd,输入:node -v

这时候,表示我们已经安装成功了。

第二步,理所当然的,"hello world" 程序

新建一个hello.js文件,里边输入:console.log("hello world !");

cmd切换到这个js的目录,输入"node hello.js",输入"hello world !",就成功了。

第三步,在浏览器中显示“hello world !”

新建一个"http.js",代码如下:

var http = require("http");
http.createServer(function(request, response) {
console.log('Server Running');
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8080);
console.log('Server running at http://127.0.0.1:8080/');

cmd中输入:"node http.js"

然后在浏览器中输入:http://127.0.0.1:8080/ 就可以看到"hello world !"了

 取消侦听:Ctrl+C  注:我把文件后缀改成.txt,一样可以运行成功

第一次学习就到这里(也是第一次写),因为同类的文章有很多,如发现雷同,敬请谅解,这是我个人的学习过程,肯定是参考了你们的资料。

原文地址:https://www.cnblogs.com/lwein/p/3830118.html