Created
April 26, 2019 08:59
-
-
Save raymondpittman/3f5d0fb1ee561e7d7481129323f8bd48 to your computer and use it in GitHub Desktop.
Just an example of not using body-parser
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 mysql = require("mysql"); | |
const app = express(); | |
const PORT = 3000; | |
app.use(express.json()); // JSON-encoded body | |
app.use(express.urlencoded({extended: true})); // URL-encoded body | |
app.set('view engine','ejs'); | |
let pool = mysql.createPool({ | |
connectionLimit: 100, | |
host: '', | |
user: '', | |
password: '', | |
database: '', | |
port: 1111, | |
}); | |
app.get(`/database`, (req, res) => { | |
// Database connection | |
pool.getConnection((error, connection) => { | |
if (error) { | |
connection.release(); | |
throw error; | |
} | |
connection.query(``, (error, row, fields) => { | |
// Query | |
}); | |
connection.release(); // End | |
}) | |
}); | |
// Post | |
app.post(`/`, (req, res) => { | |
console.log(req.body); | |
/* | |
If we sent a form post request with | |
key : value | |
We can access doing | |
req.body.key | |
So if it was age it would be | |
req.body.age | |
*/ | |
}); | |
// Get | |
app.get(`/`, (req, res) => { | |
res.send('Running :3000') | |
}); | |
app.listen(PORT, () => { console.log(`Listening -> ${PORT}`);}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment