Skip to content

Instantly share code, notes, and snippets.

@stevesohcot
Created September 17, 2021 17:41
Show Gist options
  • Select an option

  • Save stevesohcot/cc15b23e83542416d46fac5b0f8f641c to your computer and use it in GitHub Desktop.

Select an option

Save stevesohcot/cc15b23e83542416d46fac5b0f8f641c to your computer and use it in GitHub Desktop.
Planet Scale data retrieval - Node.js on Windows
const express = require('express')
const app = express()
const port = 3000
const fs = require('fs');
const mysql = require('mysql');
app.get('/', (req, res) => {
res.send('Hello World!')
})
var sql = 'select * from users';
app.get('/users', (req, res) => {
connection.query(sql, function (err, rows, fields) {
if (err) throw err
res.send(rows)
})
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
const connection = mysql.createConnection({
host: 'hostNameHere',
user: 'userNameHere',
password: 'passwordHere',
database: 'dbHere',
ssl: {
ca: fs.readFileSync('C:\\temp\\cacert.pem')
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment