Guest User

Untitled

a guest
Dec 13th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. const express = require('express');
  2. const app = express();
  3.  
  4. const {Client} = require('pg');
  5. const client = new Client({
  6. user: 'Recipe Manager',
  7. host: 'localhost',
  8. database: 'Recipes',
  9. password: null,
  10. port: 5432,
  11. });
  12.  
  13. const path = require('path');
  14. app.use(express.static(path.join(__dirname, 'public')));
  15.  
  16. const routes = require('./routes');
  17.  
  18. const bodyparser = require('body-parser');
  19. app.use(bodyparser.urlencoded({ extended: false}));
  20. app.use(bodyparser.json());
  21.  
  22.  
  23. // Initiliaze EJS as the view engine for our application
  24. app.set('view engine', 'ejs');
  25.  
  26. // Homepage
  27. app.get('/', routes.home);
  28.  
  29. // Test
  30. app.get('/test', function(req, res) {
  31. client.connect();
  32. client.query('SELECT name FROM "Recipes"', (err, result) => {
  33. if (err) {
  34. console.log(err);
  35. } else {
  36. result.render('test', {recipes: result.rows});
  37. client.end();
  38. }
  39. });
  40. });
  41. // Initiate port for localhost or production
  42. app.listen(process.env.PORT || 3000);
Add Comment
Please, Sign In to add comment