Skip to content

Instantly share code, notes, and snippets.

@seanconnelly34
Created May 15, 2020 22:23
Show Gist options
  • Save seanconnelly34/49db0e4021dff138b04c7115ea3897a8 to your computer and use it in GitHub Desktop.
Save seanconnelly34/49db0e4021dff138b04c7115ea3897a8 to your computer and use it in GitHub Desktop.
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