Created
March 26, 2021 11:43
-
-
Save varsubham/e25848504a170a246b4d72f6df46b21e to your computer and use it in GitHub Desktop.
sample nodejs backend
This file contains 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 connection = mysql.createPool({ | |
connectionLimit: 10, | |
host: process.env.MYSQL_HOST || "localhost", | |
user: process.env.MYSQL_USER || "root", | |
password: process.env.MYSQL_PASSWORD || "password", | |
database: process.env.MYSQL_DATABASE || "test", | |
}); | |
app.get("/", (req, res) => { | |
connection.query("SELECT * FROM Student", (err, rows) => { | |
if (err) { | |
res.json({ | |
success: false, | |
err, | |
}); | |
} else { | |
res.json({ | |
success: true, | |
rows, | |
}); | |
} | |
}); | |
}); | |
app.listen(5000, () => console.log("listining on port 5000")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment