【问题标题】:Deployment error in heroku node.js applicationheroku node.js 应用程序中的部署错误
【发布时间】:2021-02-12 05:32:51
【问题描述】:

我正在尝试将应用程序部署到 heroku,但它一直显示此错误 errno 1
我的错误

2020-10-29T17:57:07.489391+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-10-29T17:26:49.468827+00:00 app[web.1]: npm ERR! errno 1
2020-10-29T17:26:49.487954+00:00 app[web.1]: npm ERR! my-website@1.0.0 start: `node app.js`
2020-10-29T17:26:49.488218+00:00 app[web.1]: npm ERR! Exit status 1
2020-10-29T17:26:49.488442+00:00 app[web.1]: npm ERR!
2020-10-29T17:26:49.488619+00:00 app[web.1]: npm ERR! Failed at the my-website@1.0.0 start script.
2020-10-29T17:26:49.488788+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我的 app.js 文件

//=============================
//GLOBAL VARIABLES
//=============================
const express = require("express"),
    mongoose = require("mongoose"),
    methodOverride = require("method-override"),
    app = express(),
    bodyParser = require("body-parser"),
    passport = require("passport"),
    expressSanitizer = require("express-sanitizer"),
    LocalStrategy = require("passport-local"),
    flash = require("connect-flash"),
    expressSession = require("express-session"),
    passportLocalMongoose = require("passport-local-mongoose"),
    Video = require("./models/videos"),
    User = require("./models/user"),
    cookieParser = require('cookie-parser'),
    MongoDBStore = require("connect-mongo")(expressSession),
    axios = require("axios"),
    Comment = require("./models/comments"),
    GoogleStrategy = require( 'passport-google-oauth2' ).Strategy,
    GitHubStrategy = require('passport-github').Strategy,
    GOOGLE_CLIENT_ID = "id",
    GOOGLE_CLIENT_SECRET = "secret",
    GITHUB_CLIENT_ID = "id",
    GITHUB_CLIENT_SECRET = "secret";
const commentRoutes = require("./routes/comments"),
videoRoutes = require("./routes/videos"),
indexRoutes = require("./routes/index");
global.googleLogin = false;
global.googleId = null;
const db_url = "mongodb+srv://blablabla"
passport.use(new GoogleStrategy({
    clientID: GOOGLE_CLIENT_ID,
    clientSecret: GOOGLE_CLIENT_SECRET,
    callbackURL: "http://localhost:3000/login/google/callback",
    passReqToCallback: true
  },
  function(request, accessToken, refreshToken, profile, done) {
    User.findOrCreate({ googleId: profile.id }, function (err, user) {
      user = profile;
      googleLogin = true;
      return done(err, user); 
    });
  }
));

passport.use(new GitHubStrategy({
  clientID: GITHUB_CLIENT_ID,
  clientSecret: GITHUB_CLIENT_SECRET,
  callbackURL: "http://localhost:3000/login/github/callback"
},
function(accessToken, refreshToken, profile, cb) {
  User.findOrCreate({ githubId: profile.id }, function (err, user) {
    user = profile
    return cb(err, user);
  });
}
));
//============================
//SETUP
//============================
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({
    extended: true
}));
const store = new MongoDBStore({
  url:db_url,
  secret:"Lauren Paredes",
  touchAfter:24*60*60
})
app.use(expressSession({
    store,
    secret: "Lauren Paredes",
    resave: false,
    saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
passport.serializeUser(function(user, done) {
    done(null, user);
  });
  
  passport.deserializeUser(function(user, done) {
    done(null, user);
  });
passport.use(new LocalStrategy(User.authenticate()));
app.use(cookieParser());
app.use(express.static("public"));
app.use(methodOverride('_method'));
mongoose.connect(db_url, {
        useNewUrlParser: true,
        useUnifiedTopology: true
    })
    .then(() => console.log("Connected to DB"))
    .catch(error => console.log(error.message));
app.use(indexRoutes);
app.use(commentRoutes);
app.use(videoRoutes);
app.use(function(req, res, next){
    global.user = req.user;
    res.locals.auth = user,
    next()
});
app.use(function(req, res, next){
  res.locals.google = googleLogin,
  next()
});
app.listen(process.env.PORT || 8080, () => {
    console.log("Puffier Fisher Website is Listening to port " + process.env.PORT);
});
module.exports = googleLogin

如果您需要更多信息,请发表评论

【问题讨论】:

  • 这是整个错误日志吗?
  • @Take-Some-Bytes,没有

标签: node.js heroku npm deployment


【解决方案1】:

我发现了问题所在,只有我的个人 IP 地址在 mongo atlas 中被列入白名单,因此我允许访问所有 IP 地址。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-10
    • 2016-02-10
    • 2017-02-04
    • 2019-12-05
    • 1970-01-01
    • 2016-09-10
    • 2017-02-09
    相关资源
    最近更新 更多