npm
npm install packagename -g //全局
npm install packagename --save //運行環境依賴
npm install packagename --save-dev //生產環境依賴
express
//跨域
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", req.headers['origin']);
res.header("Access-Control-Allow-Headers", "x-token,x-uid,x-token-check,x-requested-with,content-type,Host");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("Access-Control-Allow-Credentials","true");
//res.header("X-Powered-By",' 3.2.1')
//res.header("Content-Type", "application/json;charset=utf-8");
next();
});
代碼片段
//格式化輸出時間
function dateFormat(date, fmt) {
if (null == date || undefined == date) return '';
let o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"h+": date.getHours(), //小時
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"S": date.getMilliseconds()//毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
Date.prototype.toJSON = function () {return dateFormat(this, 'yyyy-MM-dd hh:mm:ss')};
Date.prototype.toString = function () {return dateFormat(this, 'yyyy-MM-dd hh:mm:ss')};
Date.prototype.toDateString = function () {return dateFormat(this, 'yyyy-MM-dd')};
Date.prototype.toTimeString = function () {return dateFormat(this, 'hh:mm:ss')};