Last active
February 13, 2021 20:14
-
-
Save FergusDevelopmentLLC/05471e1965de232f4434a8624c8949dc 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 utils = require('./utils') | |
const bodyParser = require('body-parser') | |
const sqlite3 = require('sqlite3').verbose() | |
const app = express() | |
app.use(bodyParser.json()) | |
app.use(bodyParser.urlencoded({ extended: true })); | |
//utils.createSeedData() | |
let db | |
let dbFileName = 'player.db' | |
app.get('/', (req, res, next) => { | |
res.status(200).json(`Hello from node-express. The current server date/time is: ${new Date()}`) | |
}) | |
app.get('/players', async (req, res, next) => { | |
db = new sqlite3.Database(dbFileName) | |
const players = await utils.getPlayers(db) | |
db.close() | |
res.status(200).json(players) | |
}) | |
app.post('/playerByEmail', async (req, res, next) => { | |
db = new sqlite3.Database(dbFileName) | |
let emailAddress = req.body.email | |
const player = await utils.getPlayerByEmail(db, emailAddress) | |
db.close() | |
res.status(200).json(player) | |
}) | |
const server = app.listen(4060, () => { | |
console.log('App listening at port %s', server.address().port) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment