【问题标题】:node server.js won't work节点 server.js 不起作用
【发布时间】:2018-08-13 12:07:26
【问题描述】:

在我的应用程序中我使用:

  • “节点”:“7.2.1”,
  • “npm”:“4.4.4”
  • “@angular/cli”:“1.4.9”,
  • “@angular/core”:“4.4.6”

我在heroku中部署我的应用程序,它构建但是当我运行它时,当我检查它显示的heroku日志时它显示“应用程序错误”

2018-03-05T18:09:46.391200+00:00 app[web.1]: - npm ERR! A complete log of this run can be found in:
2018-03-05T18:09:46.391279+00:00 app[web.1]: - npm ERR!     /app/.npm/_logs/2018-03-05T18_09_46_383Z-debug.log

在哪里可以找到这些 .log 文件?

当我运行“node server.js”时,它仍然在等待而不做或显示任何东西

这是我的 server.js 文件

    // server.js
const express = require('express');
const app = express();
const path = require('path');

// Run the app by serving the static files
// in the dist directory
app.use(express.static(__dirname + '/dist'));
// Start the app by listening on the default
// Heroku port
app.listen(process.env.PORT || 8080);

app.use(function (req, res, next) {
  res.header("Access-Control-Allow-Origin", '*');
  res.header("Access-Control-Allow-Credentials", true);
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
  res.header("Access-Control-Allow-Headers", 'Origin,X-Requested-With,Content-Type,Accept,content-type,application/json');
  next();
});
app.get('/*', function (req, res) {

  var origin = req.get('origin');
  res.sendFile(path.join(__dirname + '/dist/index.html'));
});

如何解决这个问题?

【问题讨论】:

    标签: node.js angular heroku npm


    【解决方案1】:

    你的日志文件的路径在这里输出:

    2018-03-05T18:09:46.391279+00:00 app[web.1]: - npm ERR!     /app/.npm/_logs/2018-03-05T18_09_46_383Z-debug.log
    

    要查看整个日志文件,请运行以下命令:

    cat /app/.npm/_logs/2018-03-05T18_09_46_383Z-debug.log
    

    希望这能帮助您找到问题所在。 另外,请确保运行 ng build 在尝试提供已编译的输出之前。

    【讨论】:

    • 感谢您的回答,这不起作用,您知道为什么“npm start”仍然被阻止并且在我关闭它之前没有执行或显示任何内容?
    猜你喜欢
    • 1970-01-01
    • 2017-02-02
    • 2020-12-26
    • 2015-10-15
    • 2017-05-18
    • 1970-01-01
    • 2018-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多