-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rest api
- Loading branch information
0 parents
commit 5114cb7
Showing
10 changed files
with
3,069 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Dependency directories | ||
node_modules | ||
|
||
# production directories | ||
build | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Simple Node Express Server | ||
|
||
rest api endpoints | ||
|
||
- get | ||
- post | ||
- patch | ||
- delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const express = require('express') | ||
const mongoose = require('mongoose') | ||
const config = require('config') | ||
const cors = require('cors') | ||
|
||
const indexRouter = require('./routes/index') | ||
const postsRouter = require('./routes/posts') | ||
|
||
const app = express() | ||
|
||
app.use(cors()) | ||
app.use(express.json()) | ||
app.use(express.urlencoded({ extended: false })) | ||
|
||
// routes | ||
app.use('/', indexRouter) | ||
app.use('/posts', postsRouter) | ||
|
||
const db = config.get('mongoURI') | ||
|
||
// connect to DB | ||
mongoose | ||
.connect(db, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
useCreateIndex: true | ||
}) | ||
.then(() => console.log('MongoDB connected...')) | ||
.catch(err => console.log(err)) | ||
|
||
// listen to port | ||
app.listen(3000, () => console.log('Server running on port 3000')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"mongoURI": "mongodb://localhost/test", | ||
"jwtSecret": "sl_myJwtSecret" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const mongoose = require('mongoose') | ||
|
||
const PostSchema = mongoose.Schema({ | ||
title: { | ||
type: String, | ||
required: true | ||
}, | ||
description: { | ||
type: String, | ||
required: true | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}) | ||
|
||
module.exports = mongoose.model('posts', PostSchema) |
Oops, something went wrong.