Created
April 19, 2024 23:20
-
-
Save RayyanNafees/5c8061c7d3bf21701554539fbac7a0fb to your computer and use it in GitHub Desktop.
Express Vento Template Engine
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
import express from 'express'; | |
import vento from 'ventojs'; | |
const app = express(); | |
app.set('views', './views'); | |
app.engine('vto', (filePath, options, callback) => | |
vento() | |
.run(filePath, options) | |
.then(({ content }) => callback(null, content)) | |
.catch((err) => callback(err)) | |
); | |
app.set('view engine', 'vto'); | |
app.get('/', (req, res) => { | |
res.render('index', { title: 'Vento', heading: 'Hello world!' }); | |
}); | |
const port = process.env.PORT || 3000; | |
app.listen(port, () => | |
console.log(`Server listening at http://localhost:${port}`) | |
); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>{{title}}</title> | |
</head> | |
<body> | |
<h1>{{heading}}</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment