Skip to content
Permalink
b2e784f842
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
30 lines (26 sloc) 854 Bytes
const express = require('express')
const nunjucks = require('nunjucks')
// Import JSON dataset
const data = require("./data.json")
const app = express()
const port = 3000
// Tell nunjucks where your template files are located (e.g., 'views' directory)
nunjucks.configure('views', {
autoescape: true,
noCache: true, // <-- Should only be true when developing
express: app
});
// Endpoint for /characters shows all characters
app.get('/characters', function (req, res) {
res.render('default.njk', {
title: "Rick and Morty",
data: data
});
});
// Endpoint for /characters/:id shows details for ONE characer
app.get('/character/:id', function (req, res) {
res.render('character.njk', { /* character data goes here */ });
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})