Skip to content

Instantly share code, notes, and snippets.

@RayyanNafees
Created April 19, 2024 23:20
Show Gist options
  • Save RayyanNafees/5c8061c7d3bf21701554539fbac7a0fb to your computer and use it in GitHub Desktop.
Save RayyanNafees/5c8061c7d3bf21701554539fbac7a0fb to your computer and use it in GitHub Desktop.
Express Vento Template Engine
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}`)
);
<!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