Created
September 17, 2021 17:33
-
-
Save stevesohcot/6eb5bae3482125d184bb2ed903ca83c8 to your computer and use it in GitHub Desktop.
Planet Scale Connect with Node.js
This file contains hidden or 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 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