Initial push, base application done
This commit is contained in:
3
DB.js
Normal file
3
DB.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
DB: 'mongodb://localhost:27017/kno-logic'
|
||||||
|
}
|
||||||
30
index.js
Normal file
30
index.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const app = express();
|
||||||
|
const PORT = 4000;
|
||||||
|
const cors = require('cors');
|
||||||
|
const mongoose = require('mongoose');
|
||||||
|
const config = require('./DB.js');
|
||||||
|
|
||||||
|
const userRoutes = require('./user.route');
|
||||||
|
|
||||||
|
// Handle MongoDB connection
|
||||||
|
mongoose.Promise = global.Promise;
|
||||||
|
mongoose.connect(config.DB, { useNewUrlParser: true, useUnifiedTopology: true }).then(
|
||||||
|
() => {
|
||||||
|
console.log('Connected to dabase');
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
console.log('Could not connect to database: ' + err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Express routes
|
||||||
|
app.use('/users', userRoutes);
|
||||||
|
|
||||||
|
// Express server
|
||||||
|
app.use(cors());
|
||||||
|
app.use(express.urlencoded({ extended: true }))
|
||||||
|
app.use(express.json());
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log('Express server running on port:', PORT);
|
||||||
|
});
|
||||||
1574
package-lock.json
generated
Normal file
1574
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
package.json
Normal file
28
package.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "kno-logic-api",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "The backend server for the kno-logic app",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/jslightham/kno-logic-api.git"
|
||||||
|
},
|
||||||
|
"author": "jslightham",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/jslightham/kno-logic-api/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/jslightham/kno-logic-api#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"body-parser": "^1.19.0",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"mongoose": "^5.12.7"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^2.0.7"
|
||||||
|
}
|
||||||
|
}
|
||||||
19
user.model.js
Normal file
19
user.model.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const mongoose = require('mongoose');
|
||||||
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
// Database schema for a user
|
||||||
|
let User = new Schema({
|
||||||
|
email: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
password: {
|
||||||
|
type: String
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
collection: 'users'
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = mongoose.model('User', User);
|
||||||
8
user.route.js
Normal file
8
user.route.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const userRoutes = express.Router();
|
||||||
|
|
||||||
|
let User = require('./user.model');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = userRoutes;
|
||||||
Reference in New Issue
Block a user