Created
December 3, 2021 04:20
-
-
Save LearnWebCode/77ee90bc2d7f1afc97fa55d9b31ea955 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
Took me a minute but I finally got through this setup. Thanks.