extract db
This commit is contained in:
parent
8bb31432c7
commit
41ec39c961
2 changed files with 17 additions and 12 deletions
|
|
@ -1,19 +1,9 @@
|
|||
const express = require('express')
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const db = require('./db')
|
||||
const app = express()
|
||||
|
||||
const blogSchema = mongoose.Schema({
|
||||
title: String,
|
||||
author: String,
|
||||
url: String,
|
||||
likes: Number,
|
||||
})
|
||||
const Blog = db.Blog
|
||||
|
||||
const Blog = mongoose.model('Blog', blogSchema)
|
||||
|
||||
const mongoUrl = 'mongodb://localhost/bloglist'
|
||||
mongoose.connect(mongoUrl)
|
||||
|
||||
app.use(express.json())
|
||||
|
||||
|
|
|
|||
15
parts/4/blogApp/src/db.js
Normal file
15
parts/4/blogApp/src/db.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
const mongoose = require('mongoose')
|
||||
|
||||
const blogSchema = mongoose.Schema({
|
||||
title: String,
|
||||
author: String,
|
||||
url: String,
|
||||
likes: Number,
|
||||
})
|
||||
|
||||
const Blog = mongoose.model('Blog', blogSchema)
|
||||
|
||||
const mongoUrl = 'mongodb://localhost/bloglist'
|
||||
mongoose.connect(mongoUrl)
|
||||
|
||||
module.exports = {Blog}
|
||||
Loading…
Add table
Add a link
Reference in a new issue