Heroku - RangeError:“port”参数必须是> = 0且< 65536

时间:2018-03-22 07:35:34

标签: node.js angular heroku mean-stack

我正在尝试将我的MEAN应用程序部署到Heroku,但它仍然遇到此错误:

RangeError: "port" argument must be >= 0 and < 65536

server.js 代码:

const express = require("express");
const path = require("path");
// var favicon = require("serve-favicon");
var logger = require("morgan");
const bodyParser = require("body-parser");
const http = require("http");
var mongoose = require("mongoose");
const dbConfig = require("./config/database");
var reload = require("reload");
var watch = require("watch");
var fs = require("fs");
const authApi = require("./src/api/auth.api");
const gameDataApi = require("./src/api/gamedata.api");
const teamsApi = require("./src/api/teams.api");
var session = require("express-session");
var passport = require("passport");
var cookieParser = require("cookie-parser");

var app = express();

// Parsers

app.use(logger("dev"));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: false }));

// Angular DIST output folder
app.use(express.static(path.join(__dirname, "dist")));
app.use(
  session({
    secret: dbConfig.secret,
    resave: false,
    saveUninitialized: true
  })
);
app.use(passport.initialize());
app.use(passport.session({}));

mongoose.Promise = require("bluebird");
mongoose
  .connect(dbConfig.databaseHeroku, { promiseLibrary: require("bluebird") })
  .then(() => console.log("Connection Succesful!"))
  .catch(err => console.error(err));

// Send all other requests to the Angular app
// app.get("*", (req, res) => {
//   res.sendFile(path.join(__dirname, "dist/index.html"));
// });

//Set Port
const port = process.env.PORT || 3000;
app.set("port", port);
// API locations
app.use("/api/auth/", authApi);
app.use("/api/gamedata/", gameDataApi);
app.use("/api/teams/", teamsApi);

const server = app.listen(port, () =>
  console.log(`Running on localhost:${port}`)
);

module.exports = app;

的package.json

"name": "pd-free-angularcli",
  "version": "1.0.1",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "client": "ng serve --proxy-config server.conf.json",
    "server": "nodemon server.js",
    "start": "npm-run-all -p client server",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true

server.conf.json

{
  "/api": {
    "target": "http://localhost:3000",
    "secure": false
  }
}

来自Heroku的应用程序日志

2018-03-22T07:38:58.319246+00:00 heroku[web.1]: State changed from crashed to starting
2018-03-22T07:39:13.474178+00:00 heroku[web.1]: Starting process with command `npm start`
2018-03-22T07:39:16.323737+00:00 app[web.1]: 
2018-03-22T07:39:16.323753+00:00 app[web.1]: > pd-free-angularcli@1.0.1 start /app
2018-03-22T07:39:16.323755+00:00 app[web.1]: > npm-run-all -p client server
2018-03-22T07:39:16.323757+00:00 app[web.1]: 
2018-03-22T07:39:17.591772+00:00 app[web.1]: 
2018-03-22T07:39:17.591798+00:00 app[web.1]: > pd-free-angularcli@1.0.1 server /app
2018-03-22T07:39:17.591801+00:00 app[web.1]: > nodemon server.js
2018-03-22T07:39:17.591802+00:00 app[web.1]: 
2018-03-22T07:39:18.036827+00:00 app[web.1]: 
2018-03-22T07:39:18.036848+00:00 app[web.1]: > pd-free-angularcli@1.0.1 client /app
2018-03-22T07:39:18.036850+00:00 app[web.1]: > ng serve --proxy-config server.conf.json
2018-03-22T07:39:18.036852+00:00 app[web.1]: 
2018-03-22T07:39:18.482968+00:00 app[web.1]: [33m[nodemon] 1.17.1[39m
2018-03-22T07:39:18.487491+00:00 app[web.1]: [33m[nodemon] to restart at any time, enter `rs`[39m
2018-03-22T07:39:18.487494+00:00 app[web.1]: [33m[nodemon] watching: *.*[39m
2018-03-22T07:39:18.492852+00:00 app[web.1]: [32m[nodemon] starting `node server.js`[39m
2018-03-22T07:39:20.238240+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2018-03-22T07:39:20.238260+00:00 app[web.1]: designed for a production environment, as it will leak
2018-03-22T07:39:20.238262+00:00 app[web.1]: memory, and will not scale past a single process.
2018-03-22T07:39:20.413307+00:00 app[web.1]: Running on localhost:53116
2018-03-22T07:39:20.562531+00:00 app[web.1]: Connection Succesful!
2018-03-22T07:39:20.980731+00:00 heroku[web.1]: State changed from starting to up
2018-03-22T07:39:23.884757+00:00 app[web.1]: net.js:1483
2018-03-22T07:39:23.884766+00:00 app[web.1]:       throw new RangeError('"port" argument must be >= 0 and < 65536');
2018-03-22T07:39:23.884767+00:00 app[web.1]:       ^
2018-03-22T07:39:23.884769+00:00 app[web.1]: 
2018-03-22T07:39:23.884771+00:00 app[web.1]: RangeError: "port" argument must be >= 0 and < 65536
2018-03-22T07:39:23.884774+00:00 app[web.1]:     at Server.listen (net.js:1483:13)
2018-03-22T07:39:23.884777+00:00 app[web.1]:     at Object.internals.testPort (/app/node_modules/portfinder/lib/portfinder.js:66:18)
2018-03-22T07:39:23.884778+00:00 app[web.1]:     at Server.onError (/app/node_modules/portfinder/lib/portfinder.js:57:15)
2018-03-22T07:39:23.884780+00:00 app[web.1]:     at Object.onceWrapper (events.js:315:30)
2018-03-22T07:39:23.884781+00:00 app[web.1]:     at emitOne (events.js:116:13)
2018-03-22T07:39:23.884783+00:00 app[web.1]:     at Server.emit (events.js:211:7)
2018-03-22T07:39:23.884785+00:00 app[web.1]:     at emitErrorNT (net.js:1387:8)
2018-03-22T07:39:23.884786+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:138:11)
2018-03-22T07:39:23.884788+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:180:9)
2018-03-22T07:39:23.908343+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-03-22T07:39:23.908347+00:00 app[web.1]: npm ERR! errno 1
2018-03-22T07:39:23.908349+00:00 app[web.1]: npm ERR! pd-free-angularcli@1.0.1 client: `ng serve --proxy-config server.conf.json`
2018-03-22T07:39:23.908350+00:00 app[web.1]: npm ERR! Exit status 1
2018-03-22T07:39:23.908352+00:00 app[web.1]: npm ERR! 
2018-03-22T07:39:23.908354+00:00 app[web.1]: npm ERR! Failed at the pd-free-angularcli@1.0.1 client script.
2018-03-22T07:39:23.908357+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-03-22T07:39:23.917763+00:00 app[web.1]: 
2018-03-22T07:39:23.918496+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-03-22T07:39:23.919129+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-03-22T07_39_23_909Z-debug.log
2018-03-22T07:39:23.973748+00:00 app[web.1]: ERROR: "client" exited with 1.
2018-03-22T07:39:23.988132+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-03-22T07:39:23.988135+00:00 app[web.1]: npm ERR! errno 1
2018-03-22T07:39:23.988137+00:00 app[web.1]: npm ERR! pd-free-angularcli@1.0.1 start: `npm-run-all -p client server`
2018-03-22T07:39:23.988139+00:00 app[web.1]: npm ERR! Exit status 1
2018-03-22T07:39:23.988146+00:00 app[web.1]: npm ERR! 
2018-03-22T07:39:23.988373+00:00 app[web.1]: npm ERR! Failed at the pd-free-angularcli@1.0.1 start script.
2018-03-22T07:39:23.988746+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-03-22T07:39:24.005494+00:00 app[web.1]: 
2018-03-22T07:39:24.005722+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-03-22T07:39:24.005885+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-03-22T07_39_23_991Z-debug.log
2018-03-22T07:39:24.137031+00:00 heroku[web.1]: State changed from up to crashed
2018-03-22T07:39:24.093333+00:00 heroku[web.1]: Process exited with status 1

环境变量

Environment Variables

问题是什么?

0 个答案:

没有答案