Permalink
Cannot retrieve contributors at this time
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?
demos-for-dmd4470-spring-2024/rick-and-morty/index.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
30 lines (26 sloc)
854 Bytes
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
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}`) | |
}) |