Skip to content

Instantly share code, notes, and snippets.

@pmeaney
Created April 10, 2018 23:43
Show Gist options
  • Save pmeaney/37e91ef6dec62eed8229bee4b1ad6429 to your computer and use it in GitHub Desktop.
Save pmeaney/37e91ef6dec62eed8229bee4b1ad6429 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