All files / src server.ts

55.56% Statements 10/18
28.57% Branches 2/7
50% Functions 1/2
55.56% Lines 10/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 351x 1x   1x 1x   1x   1x 1x 1x                                       1x     1x  
import { app } from "./app";
import http from "http";
 
const port = process.env.PORT || "3000";
app.set("port", port);
 
const server = http.createServer(app);
 
server.listen(port);
server.on("error", onError);
server.on("listening", onListening);
 
function onError(error: Error | any) {
  if (error.syscall !== "listen") {
    throw error;
  }
 
  switch (error.code) {
    case "EACCES":
      console.error(`Port ${port} requires elevated privileges`);
      process.exit(1);
    case "EADDRINUSE":
      console.error(`Port ${port} is already in use`);
      process.exit(1);
    default:
      throw error;
  }
}
 
function onListening() {
  console.log(`Server successfully started. Listening on ${port}`);
}
 
export { server };