我已经在我的localhost上成功运行了我的nodejs应用程序,但是当我在heroku上部署它时,构建成功,但是当我使用" heroku logs&#时,我得到了#34;应用程序错误" 34;,它显示如下: console screenshot
我无法弄清楚我的应用程序出了什么问题,希望得到你的帮助,谢谢!
这是我的package.json
{
"main": "index.js",
"scripts": {
"test": "mocha --harmony test",
"start": "cross-env NODE_ENV=production pm2 start index.js --node-args='--harmony' --name 'adolt-blog'"
},
...
"dependencies": {
"config-lite": "^1.5.0",
"connect-flash": "^0.1.1",
"connect-mongo": "^1.3.2",
"cross-env": "^3.1.3",
"ejs": "^2.5.2",
"express": "^4.14.0",
"express-formidable": "^1.0.0",
"express-session": "^1.14.2",
"express-winston": "^2.0.0",
"marked": "^0.3.6",
"moment": "^2.17.0",
"mongolass": "^2.3.2",
"objectid-to-timestamp": "^1.3.0",
"sha1": "^1.1.1",
"winston": "^2.3.0",
"pm2": "^2.2.3",
"mocha": "^3.2.0"
}
}
和index.js
var path = require('path');
var express = require('express');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var flash = require('connect-flash');
var config = require('config-lite');
var routes = require('./routes');
var pkg = require('./package');
var winston = require('winston');
var expressWinston = require('express-winston');
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
name: config.session.key,
secret: config.session.secret,
cookie: {
maxAge: config.session.maxAge
},
store: new MongoStore({
url: config.mongodb
}),
saveUninitializedSession: true,
resaveSession: true
}));
app.use(flash());
app.use(require('express-formidable')({
uploadDir: path.join(__dirname, 'public/img'),
keepExtensions: true
}));
app.locals.blog = {
// title: pkg.name,
// description: pkg.description
title: 'Adolt\'s Blog',
description: 'Learn Node.js'
};
app.use(function (req, res, next) {
res.locals.user = req.session.user;
res.locals.success = req.flash('success').toString();
res.locals.error = req.flash('error').toString();
next();
});
app.use(expressWinston.logger({
transports: [
new (winston.transports.Console)({
json: true,
colorize: true
}),
new winston.transports.File({
filename: 'logs/success.log'
})
]
}));
routes(app);
app.use(expressWinston.errorLogger({
transports: [
new winston.transports.Console({
json: true,
colorize: true
}),
new winston.transports.File({
filename: 'logs/error.log'
})
]
}));
if (module.parent) {
module.exports = app;
} else {
const port = process.env.PORT;
app.listen(port, function () {
console.log(`${pkg.name} listening on port ${port}`);
});
}
答案 0 :(得分:1)
感谢@Lucas Katayama的帮助,问题终于解决了。
首先,根据use-pm2-with-cloud-providers添加main.js
。
然后像这样修改Procfile
web: node main.js
最后,重建您的应用并查看它是否有效!
希望它可以提供帮助!祝你好运!