//index.js
//npm install express
//npm install ejs
import express from 'express'
import path from 'path'
const app = express()
const port = process.env.PORT || 3000
process.env.TZ = "Asia/Phnom_Penh"
const __dirname = path.resolve()
import index from './routes/index.js'
import admin from './routes/admin.js'
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.urlencoded({extended:false}))
app.use(express.json())
app.use('/',index)
app.use('/admin',admin)
app.listen(port,function(){
console.log(`This application is listening to the port: ${port}`)
})
export default app
//routes/index.js
import express from 'express'
const index = express.Router()
index.get('/',(req,res)=>{
res.render('base')
})
export default index
//routes/admin.js
import express from 'express'
const admin = express.Router()
admin.get('/',(req,res)=>{
res.render('base')
})
export default admin
<!--views/base.ejs-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Express.js Web Framework</title>
<link href="/fonts/setup.css" rel="stylesheet">
<link href="/styles/base.css" rel="stylesheet">
<script src="/scripts/jquery.js"></script>
</head>
<body>
<p>Welcome to Khmer Web Blog Engine.</p>
</body>
</html>
/* public/styles/base.css */
body{
font: 14px/1.5 Vidaloka, OdorMeanChey;
}