Skip to content

Commit a3beef0

Browse files
committed
My first initial commit
0 parents  commit a3beef0

9 files changed

Lines changed: 748 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## RESTFul API Complete Routes

config/db.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const mongoose = require('mongoose')
2+
const config = require('config')
3+
const db = config.get('mongoURI')
4+
const log = console.log
5+
6+
// Connect Database
7+
const connectDB = async () => {
8+
try {
9+
await mongoose.connect(db, {
10+
useNewUrlParser: true,
11+
useCreateIndex: true,
12+
useFindAndModify: false
13+
})
14+
15+
log('MongoDB Connected...')
16+
} catch (error) {
17+
console.error(error.message)
18+
process.exit(1)
19+
}
20+
}
21+
22+
// Export DB
23+
module.exports = connectDB

config/default.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"mongoURI": "mongodb://127.0.0.1:27017/rest-ful-api"
3+
}

models/Post.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const mongoose = require('mongoose')
2+
3+
// Post Schema
4+
const PostSchema = mongoose.Schema(
5+
{
6+
title: {
7+
type: String,
8+
require: true,
9+
trim: true
10+
},
11+
slug: {
12+
type: String,
13+
trim: true
14+
},
15+
image: {
16+
type: String,
17+
require: true,
18+
trim: true
19+
},
20+
content: {
21+
type: String,
22+
require: true,
23+
trim: true
24+
},
25+
date: {
26+
type: Date,
27+
default: Date.now
28+
}
29+
},
30+
{
31+
timestamps: true
32+
}
33+
)
34+
35+
// export Model
36+
module.exports = mongoose.model('Post', PostSchema)

0 commit comments

Comments
 (0)