Skip to content

Instantly share code, notes, and snippets.

@krisb1220
Created May 12, 2020 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisb1220/10de3df1befdea28572f1b5411937001 to your computer and use it in GitHub Desktop.
Save krisb1220/10de3df1befdea28572f1b5411937001 to your computer and use it in GitHub Desktop.
Throwing a Syntax Error ???
{
"name": "fcc-exercise-tracker",
"version": "0.1.0",
"description": "A REST API project, part of Free Code Camp's curriculum",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.17.1",
"mongoose": "^5.9.13",
"mongodb": "^3.5.7",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"shortid": "^2.2.15"
},
"engines": {
"node": "6.9.1"
},
"repository": {
"url": "https://gomix.com/#!/project/welcome-project"
},
"license": "MIT",
"keywords": [
"node",
"gomix",
"express"
]
}
"use strict";
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const API = require("./api/api.js");
app.use(cors())
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.use(express.static('public'))
app.get('/', (req, res) => {
res.sendFile(__dirname + '/views/index.html')
});
// Not found middleware
app.use((req, res, next) => {
return next({status: 404, message: 'not found'})
})
// Error Handling middleware
app.use((err, req, res, next) => {
let errCode, errMessage
if (err.errors) {
// mongoose validation error
errCode = 400 // bad request
const keys = Object.keys(err.errors)
// report the first validation error
errMessage = err.errors[keys[0]].message
} else {
// generic or custom error
errCode = err.status || 500
errMessage = err.message || 'Internal Server Error'
}
res.status(errCode).type('txt')
.send(errMessage)
});
app.post("/api/exercise/newuser", async function(req, res){
API.makeNewUser();
});
const listener = app.listen(process.env.PORT || 3000, () => {
console.log('Your app is listening on port ' + listener.address().port)
})
var a = new API.Exercise("test", "12/20/1999")
var b = new API.Exercise("test", null)
console.log(a);console.log(b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment