在express.js中使用supervisor自动重新加载

时间:2015-11-13 14:21:20

标签: node.js express supervisor

我的package.json

{
  "name": "lays-vroubek",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "supervisor ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.13.2",
    "cookie-parser": "~1.3.5",
    "debug": "~2.2.0",
    "express": "~4.13.1",
    "jade": "~1.11.0",
    "less-middleware": "^2.0.1",
    "morgan": "~1.6.1",
    "reload": "^0.7.0",
    "serve-favicon": "~2.3.0",
    "supervisor": "^0.9.1"
  }
}

我的app.js

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var lessMiddleware = require('less-middleware');

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(lessMiddleware(path.join(__dirname, 'public'), {
      force: true,
      debug: true,
      once: false
}));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});

module.exports = app;

我使用comand运行我的应用程序:"$ DEBUG=lays-vroubek:* npm start"但是如果没有任何错误消息(应用程序运行),则自动重新加载不起作用

  

lays-vroubek@0.0.0 start /Users/jan.michalik/Workspace/Sites/lays-vroubek   主管./bin/www

运行node-supervisor   程序' ./ bin / www'    - 观察'。'   --extensions&node; js,/ bin / www'   --exec'节点'

使用&节点启动子进程./bin/www' 观看目录&Users/jan.michalik/Workspace/Sites/lays-vroubek'为了改变。 按rs重新启动该过程。   lays-vroubek:服务器侦听端口3000 + 0ms

任何帮助?

1 个答案:

答案 0 :(得分:1)

例如,您有一个名为backend的快速应用。比你可以使用

DEBUG=backend:* supervisor -w server -e ejs,js,json bin/www

如果在server dir中更改了ejs,js或json文件中的任何一个(通常,我将我的快速应用程序放入server目录),则

自动重启表达应用程序