Task: Add express and nodejs application with TypeScript , Prettier and Husky

This commit is contained in:
2021-09-13 17:49:01 +07:00
parent cb4fa14781
commit 7b402b0559
11 changed files with 343 additions and 1 deletions

1
src/app.config.ts Normal file
View File

@@ -0,0 +1 @@
export const SERVER_PORT = process.env.SERVER_PORT || 3000

5
src/app.ts Normal file
View File

@@ -0,0 +1,5 @@
// app config
import "./dotenv"
// core app
import "./server"

3
src/dotenv.ts Normal file
View File

@@ -0,0 +1,3 @@
import dotenv from "dotenv"
dotenv.config()

23
src/server.ts Normal file
View File

@@ -0,0 +1,23 @@
import { createServer } from "http"
import Express from "express"
import { SERVER_PORT } from "./app.config"
// get current host id
const hostId = `${require("os").hostname()}#${process.pid}`
const app = Express()
const httpServer = createServer(app)
console.log(
`Application server running on: ${hostId} at port: ${SERVER_PORT} and started at: ${Date()}`
)
httpServer.listen(SERVER_PORT)
app.get("/", (req, res) => {
res.type("json")
res.send({
message: `Instance id: ${hostId}`,
status: "OK",
})
})