1

我的 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;

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

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

使用程序 './bin/www' --watch '.' 运行节点主管 --extensions 'node,js,/bin/www' --exec 'node'

使用 'node ./bin/www' 启动子进程 观察目录 '/Users/jan.michalik/Workspace/Sites/lays-vroubek' 以进行更改。按 rs 重新启动进程。lays-vroubek:服务器监听端口 3000 +0ms

有什么帮助吗?

4

1 回答 1

1

例如,您有一个名为backend. 比你可以使用

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

如果在 dir 中更改了任何 ejs、js 或 json 文件,则自动重启 express 应用程序server(通常,我将 express 应用程序放入serverdir 中)

于 2017-10-25T21:08:02.480 回答