Created
December 4, 2021 22:02
-
-
Save pankaj-gecko/cbed3b716779a82b91325f7e7d55826d to your computer and use it in GitHub Desktop.
This file contains 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
import Express from 'express'; | |
import { URL } from 'url'; | |
import Hbs from 'hbs'; | |
//This code does not works for me since I am using 'Express' function directly. | |
const __filename = new URL('',import.meta.url).pathname; | |
const publicDirectoryPath = new URL('../public', import.meta.url).pathname; | |
const templateDirectoryPath = new URL('../templates/views', import.meta.url).pathname; | |
Express().use(Express.static(publicDirectoryPath)); | |
Express().set('view engine', 'hbs'); | |
Express().set('views', templateDirectoryPath); | |
//Main code starts here | |
Express().get('/', (req,res) => { | |
res.send("<h1>Hello World</h1>"); | |
}); | |
Express().listen(3000, () => { | |
console.log("Listening on Port 3000"); | |
}); |
This file contains 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
import Express from 'express'; | |
import { URL } from 'url'; | |
import Hbs from 'hbs'; | |
const __filename = new URL('',import.meta.url).pathname; | |
//This function works fine as expected | |
const publicDirectoryPath = new URL('../public', import.meta.url).pathname; | |
const templateDirectoryPath = new URL('../templates/views', import.meta.url).pathname; | |
const app = Express(); | |
app.use(Express.static(publicDirectoryPath)); | |
app.set('view engine', 'hbs'); | |
app.set('views', templateDirectoryPath); | |
//Main code starts here. | |
app.get('/', (req,res) => { | |
res.send("<h1>Hello World</h1>"); | |
}); | |
app.listen(3000, () => { | |
console.log("Listening on Port 3000"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment