Load static html pages
// npm init -y
//npm install express --save
const path = require('path')
const express = require('express')
console.log(__dirname);
console.log(path.join(__dirname,'../public'));
const app = express()
const publicDirPath = path.join(__dirname,'../public')
app.use(express.static(publicDirPath))
// app.com
// app.com/help
// app.com/about
app.get('/help', (req, res) => {
res.send([
{
name:'rinto',
age:10
},
{
name:'neil',
age:20
}
])
})
app.get('/wheather', (req, res) => {
res.send('Currenty weather')
})
// http://localhost:3000/
app.listen(3000, () => {
console.log('Server is up on 3000')
})
// Create HTML
// index.html
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Weather</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' media='screen' href='main.css'>
<script src='main.js'></script>
</head>
<body>
<h1>HTML Page</h1>
</body>
</html>
// Create about page
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Weather</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' media='screen' href='main.css'>
<script src='main.js'></script>
</head>
<body>
<h1>About Page</h1>
</body>
</html>