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/client-side/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.
59 lines (46 sloc)
1.21 KB
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') | |
const app = express() | |
const port = 3000 | |
// Configure Nunjucks | |
nunjucks.configure('views', { | |
autoescape: true, | |
express: app, | |
noCache: true | |
}); | |
const emojis = require('./static/emojis.json') | |
// Static Files | |
app.use(express.static('static')) | |
app.get('/', (req, res) => { | |
res.send('Hello World!') | |
}) | |
// Express Write the HTML | |
app.get('/emoji-lister-server-side.html', (req, res) => { | |
let html = `<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Emoji Lister</title> | |
</head> | |
<body> | |
<h1>Emoji Lister</h1> | |
<main>` | |
for (const item in emojis) { | |
html += `<img src="${emojis[item]}" alt="${item}" width="100" height="100">` + "\n" | |
} | |
html += `</main></body></html>` | |
res.send(html) | |
}) | |
// Nunjucks Writes the HTML | |
app.get('/emoji-lister-nunjucks.html', (req, res) => { | |
let html = nunjucks.render('emoji.njk', { | |
emojis: emojis, | |
title: "Emoji Lister", | |
bodyClass: 'emoji' | |
}) | |
res.send(html) | |
}) | |
app.listen(port, () => { | |
console.log(`Example app listening on port ${port}`) | |
}) |