Advertisement
Guest User

Untitled

a guest
Jan 11th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. const express = require('express');
  2. const app = express();
  3. const _ = require('lodash');
  4. const mysql = require('promise-mysql');
  5.  
  6. const getConnection = () => mysql.createConnection({
  7. host: 'training-2019-01-11.cg3svzfufeu1.us-east-2.rds.amazonaws.com',
  8. user: 'root',
  9. password: '12345678',
  10. database: 'memes'
  11. });
  12.  
  13. app.get('/', (req, res) => {
  14. return getConnection().then((conn) => {
  15. let selectQuery = conn.query(`select * from memes`);
  16.  
  17. return selectQuery.then((memes) => {
  18. conn.end();
  19. const meme = _.sample(memes);
  20. return res.send("A very good meme is: " + meme.name);
  21.  
  22. });
  23.  
  24. });
  25. });
  26.  
  27. app.listen(3000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement