同步请求
const request = require('request');
function requestPromise(options) {
return new Promise(function (resolve, reject) {
request(options, function(err, response, body) {
if (err) reject(err);
resolve(body);
});
});
}
let body = await requestPromise({
url: 'http://127.0.0.1:8888/Payserver',
method: "POST",
//json 就是body
form: requestData
});
同理 其他请求模块也可以用类似的方法构造!
删除属性
我尝试用delete 但是有时候无效 没深入!
//将cardObj中的属性id name 删除后 赋值给data
let {id,name,...data} = cardObj
Sequelize查询返回很多数据
return Nser.findOne({
where: wh,
raw: true //只返回查询的语句
});
nodemon有时候无效
–未解决
pm2 常用指令
停止:pm2 stop app_name|app_id
删除:pm2 delete app_name|app_id
重启:pm2 restart app_name|app_id
停止所有:pm2 stop all
查看所有的进程:pm2 list
查看所有的进程状态:pm2 status
查看某一个进程的信息:pm2 describe app_name|app_id
参数说明
--watch:监听应用目录源码的变化,一旦发生变化,自动重启。如果要精确监听、不见听的目录,最好通过配置文件
-i --instances:启用多少个实例,可用于负载均衡。如果-i 0或者-i max,则根据当前机器核数确定实例数目,可以弥补node.js缺陷
--ignore-watch:排除监听的目录/文件,可以是特定的文件名,也可以是正则。比如--ignore-watch="test node_modules "some scripts"
-n --name:应用的名称,查看应用信息的时候可以用到
-o --output <path>:标准输出日志文件的路径,有默认路径
-e --error <path>:错误输出日志文件的路径,有默认路径
--interpreter <interpreter>:the interpreter pm2 should use for executing app (bash, python...)
如完整参数命令:
pm2 start demo.js --watch -i 2 //开启2个进程
pm2 start app.js -i max //根据机器CPU核数,开启对应数目的进程
配置nginx
修改nginx.conf
安装nginx后,nginx的默认目录是/etc/nginx
在该目录中有nginx.conf文件,输入如下命令,使用vi打开该文件
vi nginx.conf
新添加
include /etc/nginx/conf.d/.conf;
include /etc/nginx/sites-enabled/;
include /etc/nginx/hosts/*.host;#新添加的一行
创建*.host文件
在/etc/nginx中创建hosts文件夹
mkdir hosts
在host文件中创建syt.host文件,文件名随便命名
在文件中添加如下内容
server {
listen 8080;#自己设置端口号
server_name syt;#自己设置项目名称
#access_log logs/host.access.log main;
location / {
root /home/ubuntu/dist;#这里写vue项目的所在地址
index index.html;#这里是vue项目的首页,需要保证dist中有index.html文件
}
error_page 500 502 503 504 /50x.html;#错误页面
}
重启nginx
nginx -s reload
访问vue项目
ip:port/index.html即可进行访问
常见错误
浏览器访问时显示403
这个问题有多种原因,我当时遇到的原因是该项目所在的文件没有权限访问
chmod -R 777 home