node.js

Node.js是什么?

  简单地说就是运行在服务器端的JavaScript,是一个基于chrome JavaScript运行时建立的平台,是一个事件驱动I/O服务端JavaScript环境,基于Google的V8引擎,V8引擎执行JavaScript的速度非常快,性能非常好。

如何在服务器端运行Node.js?

  1、在编辑器创建一个Nodejs文件,然后创建helloworld.js文件,然后在helloworld.js写下面一段代码

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

  2、打开cmd控制台,找到文件夹的位置,运行node  helloworld.js命令,可以看出命令行输出Server running at http://localhost:8080/ 如下图

  

  在浏览器端输入http://localhost:8080/可以在页面看到helloworld!

安装express:

   1、全局安装命令:npm install express -gd  

     当前文件夹下安装命令:npm install express 

     安装成功后,命令行会提示 npm info ok。完成后只是说可以require了要想在terminal下用express生成project,还需要 npm install -g express-generator。

     -g代表安装到NODE_PATH的lib里面,而-d代表把相依性套件也一起安装。如果沒有-g的话会安装目前所在的目录(会建立一个node_modules的文件夹)。

  目录:

    2、进入npm  init

    3、npm install express-generator -g    

    4、express  

怎么利用现有的框架(Express),快速在服务器端搭建Node.js服务?

Node.js怎么处理路由控制?

Node.js怎么处理数据请求?

原文地址:https://www.cnblogs.com/qing1304197382/p/5522324.html