0.1.3 • Published 7 years ago
@chriscalo/start-server
Licence
MIT
Version
0.1.3
Deps
1
Size
249 kB
Vulns
0
Weekly
0
@chriscalo/start-server
DEPRECATED. See express-start
Simple utility for starting an express server with automatic port selection.
Installation:
npm install @chriscalo/start-server
# or
yarn add @chriscalo/start-server
Usage:
const express = require("express");
const { start } = require("@chriscalo/start-server");
const server = express();
server.get("/", (req, res) => {
res.send("Hello, world!");
});
start(server);
// or
start(server, 3000);
The logic for selecting a port is as follows:
- if
process.env.PORTis defined, it tries that port and fails if it's not available - the
portparameter instart(server, port)defaults to8000when a falsy value or no value is provided - it first tries to listen on
port, incrementing it until one is found that is available (8001,8002,8003, etc)
Example output:
App listening on port 8000
Press Ctrl+C to quit.