Skip to content

Instantly share code, notes, and snippets.

@pavanbelagatti
Created August 22, 2023 09:37
Show Gist options
  • Save pavanbelagatti/775117f7bbbd611d69760fa4e032407d to your computer and use it in GitHub Desktop.
Save pavanbelagatti/775117f7bbbd611d69760fa4e032407d to your computer and use it in GitHub Desktop.
nodejs server file
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