Skip to content

Commit

Permalink
add route and first controller function
Browse files Browse the repository at this point in the history
  • Loading branch information
Djibba committed Feb 23, 2022
1 parent 6e4d1d8 commit 1112ba4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 2 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const mongoose = require('mongoose');
const task = require('./routes/taskRoute');

const app = express();

Expand All @@ -28,9 +29,7 @@ app.use(session({
cookie: { secure: false }
}));

app.get('/', (req, res, next) => {
res.send("hello");
});
app.use('/',task);


module.exports = app;
9 changes: 9 additions & 0 deletions controllers/taskController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const mongoose = require('mongoose');

const getAllTasks = (req, res, next) => {
res.send('all tasks');
};

module.exports = {
getAllTasks
};
2 changes: 1 addition & 1 deletion db/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ const mongoose = require('mongoose');

const connectionString = 'mongodb+srv://djibba:[email protected]/taskDatabase?retryWrites=true&w=majority';

mongoose.connect(connectionString)
mongoose.connect(connectionString, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('Connection for database successfully !'))
.catch((err) => console.log(err));
9 changes: 9 additions & 0 deletions routes/taskRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const express = require('express');
const router = express.Router();
const {
getAllTasks
} = require('../controllers/taskController');

router.route('/api/tasks').get(getAllTasks);

module.exports = router;

0 comments on commit 1112ba4

Please sign in to comment.