Task: Add express and nodejs application with TypeScript , Prettier and Husky
This commit is contained in:
1
src/app.config.ts
Normal file
1
src/app.config.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const SERVER_PORT = process.env.SERVER_PORT || 3000
|
||||
5
src/app.ts
Normal file
5
src/app.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// app config
|
||||
import "./dotenv"
|
||||
|
||||
// core app
|
||||
import "./server"
|
||||
3
src/dotenv.ts
Normal file
3
src/dotenv.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import dotenv from "dotenv"
|
||||
|
||||
dotenv.config()
|
||||
23
src/server.ts
Normal file
23
src/server.ts
Normal 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",
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user