Skip to content

Instantly share code, notes, and snippets.

@LearnWebCode
Created April 16, 2025 20:58
Show Gist options
  • Save LearnWebCode/743937f534c635c73e7efb11654e5842 to your computer and use it in GitHub Desktop.
Save LearnWebCode/743937f534c635c73e7efb11654e5842 to your computer and use it in GitHub Desktop.
{
"name": "our-example-backend",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"cors": "^2.8.5",
"express": "^5.1.0"
}
}
const express = require("express")
const cors = require("cors")
const app = express()
app.use(cors())
app.get("/", async (req, res) => {
await new Promise(resolve => setTimeout(resolve, 3000))
const ourNumber = Math.floor(Math.random() * (1000000 - 1 + 1)) + 1
res.json({ content: "Welcome to our homepage. Thank you for stopping by and we hope you enjoy your stay.", ourNumber })
})
app.get("/about", async (req, res) => {
await new Promise(resolve => setTimeout(resolve, 3000))
const ourNumber = Math.floor(Math.random() * (1000000 - 1 + 1)) + 1
res.json({ content: "Our company has been around for 20 years and counting. We are committed to excellence.", ourNumber })
})
app.get("/random", async (req, res) => {
await new Promise(resolve => setTimeout(resolve, 3000))
const pets = ["Meowsalot", "Whiskers", "Purrfect", "Fluffy", "Barksalot", "Purrsloud", "Clawsome", "Furry Friend", "Sassy", "Whiskerface", "Tailspin", "Cuddlebug", "Pounce de Leon", "Furry McFlufferson"]
const randomPet = pets[Math.floor(Math.random() * pets.length)]
const randomWeight = Math.floor(Math.random() * (50 - 4 + 1)) + 4
return res.json({
pet: randomPet,
weight: randomWeight
})
})
app.listen(3000, () => {
console.log("Example app listening on port 3000")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment