-
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.
- Loading branch information
Showing
6 changed files
with
100 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,4 @@ | ||
/node_modules | ||
|
||
package-lock.json | ||
default.json |
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 config = require('config'); | ||
const db = config.get('mongoURI'); | ||
|
||
const connectDB = async () => { | ||
try { | ||
await mongoose.connect(db, { | ||
useUnifiedTopology: true, | ||
useNewUrlParser: true | ||
}); | ||
|
||
console.log('Mongo connected...') | ||
} catch (err) { | ||
console.log(err.message); | ||
} | ||
}; | ||
|
||
module.exports = connectDB; |
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,26 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const UserSchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
unique: true | ||
}, | ||
password: { | ||
type: String, | ||
required: true | ||
}, | ||
avatar: { | ||
type: String | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
module.exports = User = mongoose.model('user', UserSchema); |
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,28 @@ | ||
{ | ||
"name": "nodedemo", | ||
"version": "1.0.0", | ||
"description": "nodeDemo", | ||
"main": "server.js", | ||
"scripts": { | ||
"start": "node server", | ||
"dev-server": "nodemon server" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/thomas367/nodeDemo.git" | ||
}, | ||
"author": "Thomas Liakos", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/thomas367/nodeDemo/issues" | ||
}, | ||
"homepage": "https://github.com/thomas367/nodeDemo#readme", | ||
"dependencies": { | ||
"config": "^3.3.0", | ||
"express": "^4.17.1", | ||
"mongoose": "^5.9.4" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^2.0.2" | ||
} | ||
} |
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,9 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
|
||
|
||
//Test route | ||
// /api/user route | ||
router.get('/', (req, res) => res.send('User route')); | ||
|
||
module.exports = router; |
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,15 @@ | ||
const express = require('express'); | ||
const connectDB = require('./config/dbConnection'); | ||
|
||
const app = express(); | ||
|
||
connectDB(); | ||
|
||
app.get('/', (req, res) => res.send('API running')); | ||
|
||
//Access user route | ||
app.use('/api/users', require('./routes/api/users')); | ||
|
||
const PORT = process.env.PORT || 5000; | ||
|
||
app.listen(PORT, () => console.log('Server started')); |