node.js - How to set port for Heroku on a Node.Js Typescript Project
问题描述
Normally, Heroku dynamically sets the port for us.
const PORT : string|number = process.env.PORT || 5000;
But how do I modify this code to accept PORT... and it's using the => shorthand with Typescript.
server.listen(port => {
console.log(`Server is listening on http://localhost:${port}`);
});
Here's the top of the server class...
import express, { Application } from "express";
import socketIO, { Server as SocketIOServer } from "socket.io";
import { createServer, Server as HTTPServer } from "http";
import path from "path";
export class Server {
private httpServer: HTTPServer;
private app: Application;
private io: SocketIOServer;
解决方案
您需要在 http.createserver 中指定应用程序模块,然后只有 express 可以通过端口携带应用程序
const PORT = process.env.PORT || 8888;
http.createServer(app).listen(PORT, () => {
console.log(PORT);
})
推荐阅读
- javascript - 处理ajax post请求时节点js-req.body为空或未定义
- html - 网页设计中 SVG 的 100% 宽度
- qpid - 将 PLAIN 添加到 Apache Qpid Broker-J 的接受 SASL 机制列表中
- python-2.7 - python boto脚本中EC2实例的DiskSpaceUtilization指标显示空响应
- javascript - 另一个组件中的提交按钮创建辅助功能问题
- java - Java ZipFileSystem 在遍历时不保留物理顺序
- android - INSTALL_FAILED_INVALID_APK 次数过多
- android - Android SDK 上的 .so 库
- c++ - 如何使用带有 OR 条件的 BOOST_STATIC_ASSERT
- sql - gorm 如何确定使用哪个表?