lesson 7
This commit is contained in:
27
nodeJS/Learning/06/src/index.ts
Normal file
27
nodeJS/Learning/06/src/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import express, { Application, Request, Response } from "express";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config({ path: "$(__dirname)/../env" });
|
||||
|
||||
const app: Application = express();
|
||||
const port: number = parseInt(process.env.PORT as string) || 3000;
|
||||
|
||||
//Setting up for EJS
|
||||
app.set("views", `./src/views`);
|
||||
app.set("view engine", "ejs");
|
||||
|
||||
//Static route
|
||||
app.use(express.static(`${__dirname}/../public`));
|
||||
|
||||
//check and send index ejs
|
||||
app.get("/", (_req: Request, res: Response): void => {
|
||||
const date = new Date().toLocaleString();
|
||||
|
||||
res.render("index", {
|
||||
time: date,
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(port, (): void => {
|
||||
console.log(`Server is running on port ${port}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user