我有这个简单的代码:
router.get('/generateTime', cors(), (req, res, next) => {
var now = new Date();
res.json({
"date": now.getDate(),
"day": now.getDay(),
"hours": now.getHours(),
"minutes": now.getMinutes(),
"month": now.getMonth(),
"seconds": now.getSeconds(),
"time": now.getTime(),
"timezoneOffset": now.getTimezoneOffset(),
"year": now.getFullYear() - 1900,
});
});
这在localhost上很好用,并导致:
{"date":12,"day":3,"hours":17,"minutes":45,"month":8,"seconds":29,"time":1536759929173,"timezoneOffset":-120,"year":118}
但是当我在Heroku上使用它时,出现应用程序错误。日志状态:
2018-09-12T13:50:25.541953 + 00:00 heroku [web.1]:状态从开始更改为崩溃
2018-09-12T13:50:32.696713 + 00:00 heroku [router]:at =错误代码= H10 desc =“应用程序崩溃”方法= GET路径=“ /” host = uczich-helper.herokuapp.com request_id = 02574304-0a4f-413c-8da5-316a07805d81 fwd =“ 109.196.117.12” dyno = connect = service = status = 503字节= protocol = https
2018-09-12T13:50:33.926344 + 00:00 heroku [router]:at =错误代码= H10 desc =“应用程序崩溃”方法= GET路径=“ /” host = uczich-helper.herokuapp.com request_id = 965dc224-3922-400e-9af3-f7b648dc49a3 fwd =“ 109.196.117.12” dyno = connect = service = status = 503字节= protocol = https
我正在使用免费的测功机。我尝试删除该应用程序并创建一个新应用程序,但是没有运气。
编辑:
这是www
文件:
#!/usr/
bin / env
node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('mailer:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '4000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
这是我的package.json
文件:
{
"name": "mailer",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"ejs": "~2.5.7",
"express": "~4.15.5",
"morgan": "~1.9.0",
"serve-favicon": "~2.4.5"
},
"devDependencies": {
"cors": "^2.8.4",
"nodemailer": "^4.6.7"
}
}
答案 0 :(得分:0)
原来,我不得不将依赖项从devDependencies
移到dependencies
。不知道为什么npm现在要这样做。