Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fully functioned todo app #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 0 additions & 6 deletions Practice/#1 code of the play list.js

This file was deleted.

11 changes: 0 additions & 11 deletions Practice/#10 File Read and Write/app.js

This file was deleted.

1 change: 0 additions & 1 deletion Practice/#10 File Read and Write/sample.txt

This file was deleted.

8 changes: 0 additions & 8 deletions Practice/#11 Asyc/app.js

This file was deleted.

1 change: 0 additions & 1 deletion Practice/#11 Asyc/input.txt

This file was deleted.

9 changes: 0 additions & 9 deletions Practice/#2 callfunction.js

This file was deleted.

4 changes: 0 additions & 4 deletions Practice/#3 dirname.js

This file was deleted.

9 changes: 0 additions & 9 deletions Practice/#4 event.js

This file was deleted.

11 changes: 0 additions & 11 deletions Practice/#5 getmodule.js

This file was deleted.

19 changes: 0 additions & 19 deletions Practice/#6 moduleexp.js

This file was deleted.

14 changes: 0 additions & 14 deletions Practice/#7 num 3.js

This file was deleted.

8 changes: 0 additions & 8 deletions Practice/#8 setInterval.js

This file was deleted.

29 changes: 0 additions & 29 deletions Practice/#9 util.js

This file was deleted.

18 changes: 18 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var express = require ('express');
var todoController = require('./controllers/todoController');

var app = express();

//set up template engine
app.set('view engine','ejs');
app.engine('ejs', require('ejs').__express);

//static files
app.use(express.static('public'));


//fire controllers
todoController(app);
//listen to port
app.listen(3000);
console.log('you are listening to port 3000');
54 changes: 54 additions & 0 deletions controllers/todoController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var bodyParser = require('body-parser');
var mongoose = require('mongoose');

//connect to database
mongoose.connect('mongodb+srv://pulsara:[email protected]/test?retryWrites=true&w=majority');

//Create a schema - this is like a blueprint
var todoSchema = new mongoose.Schema({
item:String
});

//create model called Todo
var Todo = mongoose.model('Todo',todoSchema);
var itemOne = Todo({item:'get flowers'}).save(function(err){
if(err) throw err;
console.log('item saves');
})

var data = [ {item:'cdddd'},{item:'vcvcvc'},{item:'ccvc'}];

var urlencodedParser = bodyParser.urlencoded({ extended: false })

module.exports = function(app){

app.get('/todo',function(req,res){
//get data from mongoDb and pass it to view
Todo.find({},function(err,data){
if(err) throw err;
res.render('todo', {todos:data});
});

});

app.post('/todo', urlencodedParser, function (req, res) {
//get data from the veiw and add it to mongodb

var newTodo = Todo(req.body).save(function(err,data){
if (err) throw err;
res.json(data);
});
//data.push(req.body);

})

app.delete('/todo/:item',function(req,res){
//delete the requested item from db

Todo.find({item:req.params.item.replace(/\-/g, " ")}).remove(function(err,data){
if(err) throw err;
res.json(data);
});
});

};
15 changes: 15 additions & 0 deletions node_modules/.bin/ejs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/ejs.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions node_modules/.bin/ejs.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/jake

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/jake.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions node_modules/.bin/jake.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/semver.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions node_modules/.bin/semver.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading