Created
August 22, 2023 09:37
-
-
Save pavanbelagatti/775117f7bbbd611d69760fa4e032407d to your computer and use it in GitHub Desktop.
nodejs server file
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
import mysql from 'mysql2/promise'; | |
import express from 'express'; | |
// TODO: adjust these connection details to match your SingleStore deployment: | |
const HOST = '<your host end point>'; | |
const USER = 'admin'; | |
const PASSWORD = '<your password>'; | |
const DATABASE = 'saman'; | |
const app = express(); | |
const port = 3009; | |
app.get('/', async (req, res) => { | |
// Create the connection | |
const conn = await mysql.createConnection({ | |
host: HOST, | |
user: USER, | |
password: PASSWORD, | |
database: DATABASE | |
}); | |
// Execute the query | |
const [rows, fields] = await conn.execute('SELECT * FROM cities'); | |
// Return the results | |
res.send(rows); | |
await conn.end(); | |
}); | |
app.listen(port, () => { | |
console.log(`App running on http://localhost:${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment