Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CRIO_BYTES
ME_NODEJS_MONGODB
Commits
8810f2af
Commit
8810f2af
authored
4 years ago
by
Aman Kumar Kesu
Browse files
Options
Download
Email Patches
Plain Diff
[middleWare, MongoDB] : Merged
parent
e7b77b10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
12 deletions
+18
-12
routes/index.js
routes/index.js
+18
-12
No files found.
routes/index.js
View file @
8810f2af
...
...
@@ -2,7 +2,6 @@ const express = require('express');
const
router
=
express
.
Router
();
const
Todos
=
require
(
'
../models/todo
'
);
const
mongoose
=
require
(
'
mongoose
'
);
const
Todos
=
require
(
'
../models/todo
'
);
let
arr
=
[
"
Do home Work
"
,
"
Play Cricket
"
];
...
...
@@ -15,17 +14,20 @@ router.get("/todos", (req,res) => {
console
.
log
(
err
);
}
else
{
res
.
send
(
allPosts
);
console
.
log
(
allTodos
);
res
.
send
(
allTodos
);
}
});
});
/* Add a TODO to the list
curl -X POST -d 'name=
redha
t' http://localhost:3000/todos
curl -X POST -d 'name=
Play Cricke
t' http://localhost:3000/todos
*/
router
.
post
(
"
/todos
"
,
(
req
,
res
)
=>
{
let
newTodo
=
req
.
body
.
name
;
let
newTodo
=
{
name
:
req
.
body
.
name
}
Todos
.
create
(
newTodo
,
(
err
,
newlyCreated
)
=>
{
if
(
err
)
{
console
.
log
(
err
);
...
...
@@ -40,13 +42,17 @@ curl -X "DELETE" -d 'name=Play Cricket' http://localhost:3000/todos
*/
router
.
delete
(
"
/todos
"
,
(
req
,
res
)
=>
{
let
deleteTodo
=
req
.
body
.
name
;
console
.
log
(
deleteTodo
);
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
){
if
(
arr
[
i
]
===
deleteTodo
)
{
arr
.
splice
(
i
,
1
);
}
}
res
.
send
(
arr
);
Todos
.
deleteOne
({
name
:
deleteTodo
},
(
err
,
result
)
=>
{
if
(
err
){
console
.
log
(
err
);
}
else
{
//console.log(result);
res
.
json
(
result
);
}
});
});
module
.
exports
=
router
;
\ No newline at end of file
module
.
exports
=
router
;
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment