Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. // load our app server using express somehow....
  2. const express = require('express')
  3. const app = express()
  4. const morgan = require('morgan')
  5. const mysql = require('mysql')
  6.  
  7. app.use(morgan('combined'))
  8.  
  9. const connection = mysql.createConnection({
  10. host: 'localhost',
  11. database: 'dbRestApi',
  12. user: 'root',
  13. password: '973f192g846',
  14. });
  15.  
  16. connection.connect(function (err) {
  17. if (err) {
  18. console.error('Error connecting: ' + err.stack);
  19. return;
  20. }
  21.  
  22. console.log('Connected as id ' + connection.threadId);
  23. });
  24.  
  25.  
  26. app.get("/users", (req, res) => {
  27. connection.query('SELECT * FROM users', function (error, results, fields) {
  28. if (error)
  29. throw error;
  30. console.log(results);
  31. res.json(result);
  32. });
  33.  
  34. });
  35.  
  36.  
  37. connection.end();
  38.  
  39.  
  40. app.get("/", (req, res) => {
  41. console.log("Responding to root route")
  42. res.send("Hello from ROOOOOT")
  43. })
  44.  
  45.  
  46. // localhost:3003
  47. app.listen(3006, () => {
  48. console.log("Server is up and listening on 3003...")
  49. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement