$ sudo npm install -g express-generator
$ npx express -e express_app
$ cd express_app
$ npm install
$ npm run start
http://192.168.34.10:3000/
$ sudo npm install -g express-generator-typescript
$ npx express-generator-typescript express_type_app
$ cd express_type_app
$ npm run start:dev
$ npm install ejs
src/routes/hello.ts
import { Request, Response, Router } from 'express' const router:Router = Router() router.get('/', function(req:Request, res:Response):void{ res.render('hello', { header:'Hello page', title: 'Hello!!', msg: 'This is HEllo page!' }) }) export default router
src/Server.ts
import helloRouter from './routes/hello' app.set('view engine', 'ejs') app.use('/hello', helloRouter)
src/views/hello.ejs
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><%= title %></title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous"> </head> <body> <h1 class="bg-primary text-white p-2"><%= header %></h1> <div class="container py-2"> <h2 class="mb-3"><%= title %></h2> <div class="alert alert-primary"> <%= msg %> </div> </div> </body> </html>
http://192.168.34.10:3000/hello
なかなか凄いわ