Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const router = express();
- var mysql = require("mysql");
- var con = mysql.createConnection({
- host: "localhost",
- user: "root",
- password: "",
- database: "light"
- });
- var pool = mysql.createPool({
- connectionLimit: 100,
- connectTimeout: 500000,
- acquireTimeout: 500000,
- queueLimit: 30,
- host: 'localhost',
- user: 'root',
- password: '',
- database: 'light',
- multipleStatements: true,
- });
- con.connect(function (err) {
- if (err) throw err;
- });
- router.get('/', (req, res, next) => {
- // res.send("hello"); // 1 WORKS
- var GetLight = function () {
- return new Promise(function (resolve, reject) {
- con.query("SELECT * FROM switch", function (err, result) {
- // res.send("hello"); //2 Dont work
- if (err) {
- return reject(err);
- } else {
- return resolve(result);
- }
- });
- });
- }
- GetLight().then(Resultat => {
- //res.status(200).json(Resultat); //3 Dont work
- }).catch(err => {
- console.log(err);
- res.status(500).json({
- error: err
- });
- });
- });
Add Comment
Please, Sign In to add comment