Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 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-03-06-rds.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. return selectQuery.then((memes) => {
  17. conn.end();
  18. const meme = _.sample(memes);
  19. return res.send(" A very good meme is " + meme.name);
  20. });
  21. });
  22. });
  23.  
  24. app.listen(3000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement