Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save stevesohcot/6eb5bae3482125d184bb2ed903ca83c8 to your computer and use it in GitHub Desktop.
Planet Scale Connect with Node.js
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!')
})
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')
}
});
connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});
connection.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment