Guest User

Untitled

a guest
May 5th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. const express = require('express');
  2. const cors = require('cors');
  3. const mysql = require('mysql');
  4. const app = express();
  5.  
  6. const SELECT_ALL_QUERY = 'SELECT * FROM project.react_test';
  7.  
  8. const connection = mysql.createConnection({
  9. host:'localhost',
  10. user:'avd',
  11. password:'password',
  12. database:'project',
  13. insecureAuth : true
  14. });
  15.  
  16. const pool = mysql.createPool({
  17. host : 'localhost',
  18. user : 'avd',
  19. password : 'password',
  20. authentication_string : 'root',
  21. insecureAuth : true
  22. });
  23.  
  24. //var pool = mysql.createPool(connection);
  25.  
  26. connection.connect(err => {
  27. if(err) {
  28. return err;
  29. }
  30. })
  31.  
  32. console.log(connection);
  33. app.use(cors());
  34. app.get('/', (req,res) => {
  35. res.send('hello from product server')
  36. });
  37.  
  38. app.get('/hola', (req,res) => {
  39. res.send('hola')
  40. });
  41.  
  42. app.get('/hotels_info', (req,res) => {
  43. connection.query(SELECT_ALL_QUERY, (err, results) => {
  44. if(err){
  45. return res.send(err)
  46. } else {
  47. return res.json({
  48. data: results
  49. })
  50. }
  51. });
  52. });
  53.  
  54. app.listen(4000, () => {
  55. console.log('Product server listining port 4000');
  56. });
Add Comment
Please, Sign In to add comment