Created
May 15, 2020 22:23
-
-
Save seanconnelly34/49db0e4021dff138b04c7115ea3897a8 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"); | |
require("./db/mongoose"); | |
const User = require("./models/user"); | |
const Task = require("./models/task"); | |
const app = express(); | |
//heroku deployment port, otherwise locally use 3000 | |
const port = process.env.PORT || 3000; | |
app.use(express.json()); | |
// Create a user | |
app.post("/users", (req, res) => { | |
const user = new User(req.body); | |
user | |
.save() | |
.then(() => { | |
res.status(201).send(user); | |
}) | |
.catch((e) => { | |
res.status(400).send(e); | |
}); | |
}); | |
// Get users | |
app.get("/users", (req, res) => { | |
User.find({}) | |
.then((users) => { | |
res.send(users); | |
console.log("fuck" + users); | |
}) | |
.catch((e) => { | |
console.log(e); | |
}); | |
}); | |
// Create a task | |
app.post("/tasks", (req, res) => { | |
const task = new Task(req.body); | |
task | |
.save() | |
.then(() => { | |
res.status(201).send(task); | |
}) | |
.catch((e) => { | |
res.status(400).send(e); | |
}); | |
}); | |
app.listen(port, () => { | |
console.log("Server listening on port " + port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment