【问题标题】:Failed at the app@1.0.0 start script This is probably not a problem with npm. There is likely additional logging output above在 app@1.0.0 启动脚本失败 这可能不是 npm 的问题。上面可能有额外的日志输出
【发布时间】:2020-09-11 16:45:48
【问题描述】:

大家好,我创建了一个 Mern stack 的小项目。我在 Heroku 上正确部署它。但是一旦我在部署后在 Heroku 上检查她,然后加载资源失败:服务器响应状态为 503(服务不可用)错误即将到来。 但是,一旦我在部署后在 cmd 中运行 heroku local,它就会正常工作。我在 heroku 设置代码下面给出。请指导我。请........

后端的package.sjon文件

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "npm install && node index",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "dependencies": {
    "config": "^3.3.1",
    "express": "~4.16.1",
    "express-fileupload": "^1.1.7-alpha.3",
    "mongoose": "^5.9.12",
    "nodemailer": "^6.4.6"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

后端的Index.js文件

var express = require('express');
var path = require('path');
const connectDB = require('./config/db')
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var studentRouter = require('./routes/student')

var app = express();

connectDB();


app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

app.use(express.static('client/build'))
app.get('/', (req, res) => {
    res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
})

app.use('/', indexRouter);
app.use('/', studentRouter);
app.use('/users', usersRouter);


if (process.env.NODE_ENV == "production") {
    app.use(express.static('client/build'))
    app.get('*', (req, res) => {
        res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
    })
}



var port = process.env.PORT || '8000';
app.listen(port, () => {
    console.log(`server run port ${port}`);
})

module.exports = app;

【问题讨论】:

标签: node.js reactjs express mongoose nodemailer


【解决方案1】:

所有这些代码都是绝对正确的。我在 mongodb atlas 中创建集群时遇到问题。问题是我在创建集群时选择了 add current ip address。而我必须选择从任何地方允许。所以现在我选择了这本书。现在它正在做正确的事情。

【讨论】:

    【解决方案2】:

    在我的例子中,在我的 MongoDB 集群中的任何地方更改 网络访问 表单,解决了这个问题。 另外,不要忘记点击restart all dynos

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-27
      • 2020-11-16
      • 1970-01-01
      • 2021-02-13
      • 2019-08-30
      • 2020-10-13
      • 2020-05-10
      • 2020-07-15
      相关资源
      最近更新 更多