Skip to content
Snippets Groups Projects
Commit 6774e9bb authored by Matias Kokko's avatar Matias Kokko
Browse files

kesken 4.7

parent 0b420272
No related branches found
No related tags found
No related merge requests found
require('dotenv').config()
const express = require('express')
const http = require('http')
const cors = require('cors')
const db = require('./utils/db')
const Blog = require('./models/blogs')
require('express-async-errors')
const app = express()
app.use(cors())
app.use(express.json())
app.get('/api/blogs', async (request, response) => {
const blogs = await Blog.find({})
response.json(blogs)
})
app.post('/api/blogs', async (request, response) => {
const blog = new Blog(request.body)
const result = await blog.save()
response.status(201).json(result)
})
app.delete('/api/blogs/:id', async (request, response) => {
const id = request.params.id
await Blog.findByIdAndDelete(id)
response.status(204).end()
})
const PORT = process.env.PORT || 3003
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`)
})
module.exports = app
\ No newline at end of file
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
"name": "web-4", "name": "web-4",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index-4-2.js", "main": "index-4-7.js",
"scripts": { "scripts": {
"start": "cross-env NODE_ENV=production node index-4-2.js", "start": "cross-env NODE_ENV=production node index-4-7.js",
"dev": "cross-env NODE_ENV=development nodemon index-4-2.js", "dev": "cross-env NODE_ENV=development nodemon index-4-7.js",
"lint": "eslint .", "lint": "eslint .",
"test": "cross-env NODE_ENV=test jest --verbose --runInBand" "test": "cross-env NODE_ENV=test jest --verbose --runInBand"
}, },
......
DELETE http://localhost:3003/api/blogs/661e911a0567b559f82cfcc0
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment