### (1)介绍 >[success] 如果你是后端程序员,想部署一些高性能的服务,那么学习Node.js也是一个非常好的选择。 ### (2)安装 >[success] 建议使用`yum install npm -y` >[info] 参考:http://www.runoob.com/nodejs/nodejs-install-setup.html ~~~ cd /usr/local/src/ wget https://nodejs.org/dist/v8.11.2/node-v8.11.2.tar.gz tar zxvf node-v8.11.2.tar.gz cd node-vxxxx ./configure --prefix=/usr/local/node/8.11.2 make make install ~~~ ### (3)DEMO ~~~ var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'application/json'}); response.end('{"state":200}'); }).listen(8888); console.log('Server running at http://127.0.0.1:8888/'); ~~~ ### (4)npm命令 >[info] **Express**:npm install express --save >[info] **mysql**:npm install mysql --save >[info] **cnpm安装**:npm install -g cnpm --registry=https://registry.npm.taobao.org npm install --registry=https://registry.npm.taobao.org 未测试: - npm config set registry=https://registry.npm.taobao.org > --------------华丽的分割线-------------- >[success] 升级npm:npm install npm -g >[success] Git[地址](https://gitee.com/linzening/node) #### (1)node.js设置响应头部 ~~~ res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS"); res.header("X-Powered-By",' 3.2.1') res.header("Content-Type", "application/json;charset=utf-8"); ~~~