//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 frontend from './routes/frontend.js'
import backend from './routes/backend.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('/',frontend)
app.use('/admin',backend)
app.listen(port,function(){
console.log(`This application is listening to the port: ${port}`)
})
export default app
//routes/frontend.js
import express from 'express'
const frontendRouter = express.Router()
frontendRouter.get('/',(req,res)=>{
res.render('base')
})
export default frontendRouter
//routes/backend.js
import express from 'express'
const backendRouter = express.Router()
backendRouter.get('/',(req,res)=>{
res.render('base')
})
export default backendRouter
<!--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;
}