Stack OverflowMediumdev.toGitHub

Nunjucks

✍️ Published on ( min read)

Getting started with nunjucks, nodejs and express

Using nunjucks from Mozilla, you can create SSR sites very quickly.

Index.js

const express = require('express');
const app = express();

const nunjucks = require('nunjucks');
const path = require('path');

nunjucks.configure('./src/views/', {
  autoescape: true,
  express: app,
});

app.set('view engine', 'njk');

app.get('/', (req, res) => {
  res.render('home', {});
})

const PORT = process.env.PORT || 8080;
app.listen(PORT);
console.log(`App started on port: ${PORT}`);