Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const app = express();
- const {Client} = require('pg');
- const client = new Client({
- user: 'Recipe Manager',
- host: 'localhost',
- database: 'Recipes',
- password: null,
- port: 5432,
- });
- const path = require('path');
- app.use(express.static(path.join(__dirname, 'public')));
- const routes = require('./routes');
- const bodyparser = require('body-parser');
- app.use(bodyparser.urlencoded({ extended: false}));
- app.use(bodyparser.json());
- // Initiliaze EJS as the view engine for our application
- app.set('view engine', 'ejs');
- // Homepage
- app.get('/', routes.home);
- // Test
- app.get('/test', function(req, res) {
- client.connect();
- client.query('SELECT name FROM "Recipes"', (err, result) => {
- if (err) {
- console.log(err);
- } else {
- result.render('test', {recipes: result.rows});
- client.end();
- }
- });
- });
- // Initiate port for localhost or production
- app.listen(process.env.PORT || 3000);
Add Comment
Please, Sign In to add comment