Skip to content

Commit

Permalink
Merge branch 'release/v0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas367 committed Mar 14, 2020
2 parents ffacb48 + e649aa7 commit 83a7158
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules

package-lock.json
default.json
18 changes: 18 additions & 0 deletions config/dbConnection.js
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;
26 changes: 26 additions & 0 deletions models/User.js
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);
28 changes: 28 additions & 0 deletions package.json
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"
}
}
9 changes: 9 additions & 0 deletions routes/api/users.js
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;
15 changes: 15 additions & 0 deletions server.js
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'));

0 comments on commit 83a7158

Please sign in to comment.