res.send(“Happy Valentine’s Day!”)

npm initnpm install express handlebars
-public (for my static content: all of my image files and my stylesheet)
-views
---layout.hbs (my main view which contained the link to the stylesheet)
---index.hbs (my homepage)
---pictures.hbs (where I’d display the picture and text pairing)
-comments.js (an array of my text content)
-pictures.js (an array of file paths that reference my photos)
-index.js (where everything comes together: import everything in and write out the display logic)
app.get(“/pictures”, (req,res) => {
const pictureIndex = Math.floor(Math.random() * pictures.length)
const commentIndex = Math.floor(Math.random() * comments.length)
res.render(path.join(__dirname,’views/pictures’),
{pictureFile: pictures[pictureIndex],
comment: comments[commentIndex]})})

--

--

--

Just your average opossum-lovin’, Doc Martens-wearin’, JavaScript-codin’ kind of gal.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Angular 8 — What is Angular and Why to use it

What is objects in javascript? How are they represented?

How to use ScopedContextData in Hot Chocolate GraphQL

Practical React: Control Render Thrashing & Rendering Performance

Test Driving the Vue Function API

Interior view of a well-dressed individual driving a car at sunset

Making Sense of JavaScript Loose vs Strict Equality

Building a Color Tool With Vanilla HTML, CSS, and JavaScript: Part One

Zero boilerplate application state with @zodiac-ui/store for Angular

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Annabelle Thomas Taylor

Annabelle Thomas Taylor

Just your average opossum-lovin’, Doc Martens-wearin’, JavaScript-codin’ kind of gal.

More from Medium

Swell 1.10.2

Interact with object

Top 5 Javascript Frameworks 2022 By Popularity