-
-
Save jaawerth/aa0f9d7e38fb783d909869e537733b93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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