Guest User

Untitled

a guest
Oct 2nd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. // Setup Express
  2. const express = require('express');
  3. const app = express();
  4. const port = 3000;
  5.  
  6. // Setup MySQL
  7. const mysql = require('mysql');
  8.  
  9. // Handle API requests
  10. app.get('/api/products', (req, res) => {
  11. const connection = mysql.createConnection({
  12. host: '192.168.99.100',
  13. user: 'root',
  14. password: 'foo123',
  15. database: 'foo.db'
  16. });
  17. connection.connect();
  18. connection.query('SELECT * FROM products LIMIT 5;', function (err, rows, fields) {
  19. if (err) {
  20. throw err;
  21. }
  22. res.json(rows);
  23. });
  24. connection.end();
  25. });
  26.  
  27. // Start dev server
  28. app.listen(port, () => console.log(`Server up! Listening ${port}.`));
Add Comment
Please, Sign In to add comment