Node
我yi癫狂
个人网站:www.k1998.xyz
展开
-
Js如何判断undefined和null
判断是否为undefinedvar example = undefined;if (typeof(example) == "undefined"){ console.log("undefined")}判断是否为nullvar example = null; if (!example && typeof(example)!='undefined' &&...原创 2020-02-19 13:13:00 · 1077 阅读 · 0 评论 -
Promise解决异步操作问题
问题:当有多个回调函数后,就无法保证其输出的顺序性了,而采用嵌套的方式虽可以解决这个问题,但是代码样式太丑,且很乱,Promise的出现就是为了解决这个问题多个回调函数var fs = require('fs'); fs.readFile('./files/1.txt','utf8',function(err,data){ if(err){ throw err; ...原创 2020-02-16 21:33:13 · 1226 阅读 · 0 评论 -
express中获取url参数
问号传参获取参数获取 http://127.0.0.1:3001/user?id=10&name=zs 中的查询参数:直接使用 req.query 获取参数即可;注意:URL 地址栏中通过 查询字符串 传递的参数,express 框架会直接解析,大家只需使用 req.query 直接获取 URL 中 查询字符串的参数;const express = requ...转载 2020-02-16 00:51:29 · 2116 阅读 · 0 评论 -
Failed to load http://localhost:3000/products: The 'Access-Control-Allow-Origin' header has a value
用node写了个接口,但是启动前端的时候一直请求不到数据,报错Failed to load http://localhost:3000/products: The ‘Access-Control-Allow-Origin’ header has a value ‘http://127.0.0.1:3000’ that is not equal to the supplied origin....原创 2020-02-12 17:06:53 · 1064 阅读 · 0 评论 -
forever以及pm2相关命令
sudo npm install forever -g启动forever start app.jsforever list停止单个forever stop [pid]停止所有forever stopall原创 2020-02-11 01:40:24 · 512 阅读 · 0 评论