Skip to content

set up server and post router #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/posts/posts-router.js
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
// implement your posts router here
const Post = require("./posts-model");
const express = require("express")
const router = express.Router()

router.get("/", (req, res) =>{
Post.find(req.query)
.then(post =>{
res.status(200).json(post);
})
.catch(err =>{
console.log(err)
res.status(500).json({
message: "err"
})
})
})

module.exports = router
12 changes: 12 additions & 0 deletions api/server.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
// implement your server here
// require your posts router and connect it here
const express = require("express")
const postRouter = require("./posts/posts-router.js")
const server = express()

server.use(express.json());
server.use("/posts/posts-model.js", postRouter)

server.get("/", (req,res) =>{
res.send('hello there')
})

module.exports = server;
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
// require your server and launch it here
const server = require('./api/server.js')

const port = 9000

server.listen(port, () => {
console.log(`\n*** Server Running on http://localhost:${port} ***\n`)
})
Loading