• node开发 npm install -g express-generator@4


    Node forever :

    1,forever start --uid test start app.js

    2,forever start --uid test start -a app.js

    3,forever list 

    4,forever stop test

    node 开发流程
    1,express nodeName ; npm install;
    2,加入Database;var mongoose = require('mongoose'); npm install mongoose --save
    var dbIpAddress = process.env.MONGO_PORT_27017_TCP_ADDR || 'localhost';
    var dbPort = process.env.MONGO_PORT_27017_TCP_PORT || '27017';
    mongoose.connect('mongodb://' + dbIpAddress + ':' + dbPort + '/menusifu', function(err) {
    if(err) {
    console.log('connection error', err);
    } else {
    console.log('DB connection successful');
    }
    });
    3,加入Log
    var logDirectory = __dirname + '/log';
    var phonePath=path.join(__dirname, '../public/'+d.merchantId+"/txt");
    mkdirp(phonePath, function (err) {
    if (err) console.log(err)
    else console.log('success');
    });
    4,app.use前加入过滤
    app.use(function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    next();
    });
    app.use('/', routes);
    5,把ERROR改成
    var errorJson={
    "11000":"duplicate key error"
    }
    if (app.get('env') === 'development') {
    app.use(function(err, req, res, next) {
    if(!!err.code){err.message=!!errorJson[err.code]?errorJson[err.code];}
    res.json({"ok":0,"message":err.message});
    });
    }

    // production error handler
    // no stacktraces leaked to user
    app.use(function(err, req, res, next) {
    if(!!err.code){err.message=!!errorJson[err.code]?errorJson[err.code];}
    res.json({"ok":0,"message":err.message});
    });

    =======================================
    if (!!err) return next(err);

  • 相关阅读:
    <iframe>相关问题
    文字描边
    jquery 设置css margin-left
    uni-app mustache表达式
    Uni-app 响应式像素upx
    Uni-app页面进入和返回
    Uni-app 生命周期
    Sql添加/删除默认值
    Uni-app初体验(创建新路由)
    Uni-app初体验(页面绑定数据)
  • 原文地址:https://www.cnblogs.com/jayruan/p/5218911.html
Copyright © 2020-2023  润新知