NPM 是 Node.js 默认的包管理工具,工作中常使用 npm i
来安装和更新依赖。
"npm i 和 npm ci 区别"继续阅读
NPM 是 Node.js 默认的包管理工具,工作中常使用 npm i
来安装和更新依赖。
"npm i 和 npm ci 区别"继续阅读
Postman 诞生于 2013 年,一开始只是 Abhinav Asthana 着手于解决 API 测试的工具,随着这个工具的使用者和需求迅速激增,Abhinav Asthana 找了他的两个前同事 Ankit Sobti 和 Abhijit Kane 一起创建了公司 Postman Inc。
"Postman 使用小技巧"继续阅读
CI(持续交付)是功能迭代后自动构建、打包、校验代码格式、跑单测、单测覆盖率,常见的就是 Webpack、Rollup、ESLint等。
CD(持续部署)是经过 CI 后,代码自动部署到服务器。
GitLab CI/CD 通 .gitlab-ci.yml
配置文件来部署。
cd project_path touch .gitlab-ci.yml
"使用 GitLab CI/CD 和阿里云 CLI 自动部署前端项目"继续阅读
从字面看 X-Real-IP 代表的是客户端请求真实的 IP 地址,这个参数没有相关标准规范,如果是直接访问的请求,可能是客户端真实的 IP 地址,但是中间若经过了层层的代理,就是最后一层代理的 IP 地址。
Nginx 中的配置
proxy_set_header X-Real-IP $remote_addr;
"X-Real-IP 与 X-Forwarded-For"继续阅读
yum install nodejs -y node -v
npm install pm2 -g ln -s /home/download/node-v8.11.1-linux-x64/lib/node_modules/pm2/bin/pm2 /usr/local/bin/pm2
package.json
"scripts": { "test": "echo \"Error: no test specified\" && exit 1", "pm2": "/home/download/node-v8.11.1-linux-x64/lib/node_modules/pm2/bin/pm2 start /web/mazey.cn/server/app.js" } or "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "pm2": "pm2 start app.js" }
npm run pm2
pm2 save pm2 startup centos
若pm2 startup centos
失败,可尝试pm2 startup
。
PM2 detected systemv but you precised centos Please verify that your choice is indeed your init system If you arent sure, just run : pm2 startup
vim /etc/nginx/conf.d/*.conf upstream nodejs { server 127.0.0.1:3000; keepalive 64; } server { listen 80; server_name domain.cn; root /web/mazey.cn; index index.html index.htm; # 网站切到/server下时走nodejs location /server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Nginx-Proxy true; proxy_set_header Connection ""; proxy_pass http://nodejs; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } }
相应的 app.js
:
const express = require('express') const app = express() let hi = 'hi' app.get('/server', (req, res, next) => { hi = `Hello Mazey!\n` next() }, (req, res) => { res.send(` ${hi} ${req.method}\n ${req.originalUrl}\n ${req.query.id}\n `) }) const server = app.listen(3000, function () { let host = server.address().address let port = server.address().port console.log('Example app listening at http://%s:%s', host, port) })
注意
若报错 Cannot GET /xxx
说明 Express 的路由没配好。