Skip to content

Instantly share code, notes, and snippets.

@jaawerth
Forked from pmeaney/simple_db_get.js
Created April 10, 2018 23:45
Show Gist options
  • Save jaawerth/aa0f9d7e38fb783d909869e537733b93 to your computer and use it in GitHub Desktop.
Save jaawerth/aa0f9d7e38fb783d909869e537733b93 to your computer and use it in GitHub Desktop.
const express = require('express')
const app = express()
var bodyParser = require('body-parser')
// knex
const environment = process.env.NODE_ENV || 'development';
const configuration = require('./knexfile')[environment];
const database = require('knex')(configuration);
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.get('/api/v1/papers', (request, response) => {
database('papers').select()
.then((papers) => {
response.status(200).json(papers);
})
.catch((error) => {
response.status(500).json({ error });
});
});
app.listen(3000, function(){
console.log('Example app listening on port 3000!')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment