Skip to content

Instantly share code, notes, and snippets.

@LearnWebCode
Created December 3, 2021 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save LearnWebCode/77ee90bc2d7f1afc97fa55d9b31ea955 to your computer and use it in GitHub Desktop.
Save LearnWebCode/77ee90bc2d7f1afc97fa55d9b31ea955 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>`)
})
@7thWardMadeMe
Copy link

Took me a minute but I finally got through this setup. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment