Skip to content

Instantly share code, notes, and snippets.

@7thWardMadeMe
Forked from LearnWebCode/index.js
Created April 17, 2023 09:30
Show Gist options
  • Save 7thWardMadeMe/b231a2e46865d97e095bed792781e464 to your computer and use it in GitHub Desktop.
Save 7thWardMadeMe/b231a2e46865d97e095bed792781e464 to your computer and use it in GitHub Desktop.
Example Express app for YouTube WSL video.
const express = require('express')
const mysql = require('mysql2/promise')
const app = express()
let db
async function go() {
db = await mysql.createConnection({
host: 'localhost',
port: 3306,
user: 'root',
password: 'example',
database: 'pets'
})
app.listen(3000)
}
go()
app.get('/', async (req, res) => {
const [users] = await db.execute('SELECT * FROM users')
console.log(users)
res.send(`<ul>${users.map(animal => `<li>${animal.name}</li>`).join('')}</ul>`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment