Guest User

Untitled

a guest
Oct 24th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. const express = require('express');
  2. const router = express();
  3. var mysql = require("mysql");
  4.  
  5. var con = mysql.createConnection({
  6. host: "localhost",
  7. user: "root",
  8. password: "",
  9. database: "light"
  10. });
  11.  
  12. var pool = mysql.createPool({
  13. connectionLimit: 100,
  14. connectTimeout: 500000,
  15. acquireTimeout: 500000,
  16. queueLimit: 30,
  17. host: 'localhost',
  18. user: 'root',
  19. password: '',
  20. database: 'light',
  21. multipleStatements: true,
  22. });
  23.  
  24. con.connect(function (err) {
  25. if (err) throw err;
  26. });
  27. router.get('/', (req, res, next) => {
  28. // res.send("hello"); // 1 WORKS
  29. var GetLight = function () {
  30. return new Promise(function (resolve, reject) {
  31. con.query("SELECT * FROM switch", function (err, result) {
  32.  
  33. // res.send("hello"); //2 Dont work
  34. if (err) {
  35. return reject(err);
  36. } else {
  37. return resolve(result);
  38. }
  39.  
  40. });
  41. });
  42. }
  43.  
  44. GetLight().then(Resultat => {
  45.  
  46. //res.status(200).json(Resultat); //3 Dont work
  47.  
  48. }).catch(err => {
  49. console.log(err);
  50. res.status(500).json({
  51. error: err
  52. });
  53. });
  54. });
Add Comment
Please, Sign In to add comment