-
-
Save 7thWardMadeMe/b231a2e46865d97e095bed792781e464 to your computer and use it in GitHub Desktop.
Example Express app for YouTube WSL video.
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 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