Created
August 11, 2019 14:05
-
-
Save rintoandrews90/b96624943995b405286b8a060d1b98cf to your computer and use it in GitHub Desktop.
Load static html pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment