diff --git a/README.md b/README.md index 301c768ba..63506a974 100644 --- a/README.md +++ b/README.md @@ -17,15 +17,7 @@ Node provides the RESTful API. Angular provides the frontend and accesses the AP ## Tutorial Series -This repo corresponds to the Node Todo Tutorial Series on [scotch.io](http://scotch.io) - -Each branch represents a certain tutorial. -- tut1-starter: [Creating a Single Page Todo App with Node and Angular](http://scotch.io/tutorials/javascript/creating-a-single-page-todo-app-with-node-and-angular) -- tut2-services: Coming Soon -- tut3-auth: Coming Soon -- tut4-sockets: Coming Soon -- tut5-redis: Coming Soon -- tut6-organization: Coming Soon +This repo corresponds to the [Node Todo Tutorial Series](http://scotch.io/series/node-and-angular-to-do-app) on [scotch.io](http://scotch.io) Happy Todo-ing! diff --git a/config/database.js b/config/database.js index ed8735ffa..cd3586632 100644 --- a/config/database.js +++ b/config/database.js @@ -1,5 +1,5 @@ module.exports = { // the database url to connect - url : 'mongodb://node:node@mongo.onmodulus.net:27017/uwO3mypu' -} \ No newline at end of file + url : 'mongodb://node:nodeuser@mongo.onmodulus.net:27017/uwO3mypu' +} diff --git a/package.json b/package.json index 0f84bec6d..26d4d0b17 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,10 @@ "main" : "server.js", "author" : "Scotch", "dependencies" : { - "express" : "~3.4.4", - "mongoose" : "~3.6.2" + "express" : "~4.7.2", + "mongoose" : "~3.6.2", + "morgan" : "~1.2.2", + "body-parser": "~1.5.2", + "method-override": "~2.1.2" } } diff --git a/public/core.js b/public/core.js index 510e43861..fdfff183c 100644 --- a/public/core.js +++ b/public/core.js @@ -16,8 +16,9 @@ function mainController($scope, $http) { $scope.createTodo = function() { $http.post('/api/todos', $scope.formData) .success(function(data) { - $scope.formData.text = ''; + $scope.formData = {}; // clear the form so our user is ready to enter another $scope.todos = data; + console.log(data); }) .error(function(data) { console.log('Error: ' + data); @@ -35,4 +36,4 @@ function mainController($scope, $http) { }); }; -} \ No newline at end of file +} diff --git a/public/index.html b/public/index.html index 4ededaff8..1814ab3fc 100644 --- a/public/index.html +++ b/public/index.html @@ -70,4 +70,4 @@

I'm a Todo-aholic {{ todos.length }} - \ No newline at end of file + diff --git a/server.js b/server.js index 9f8736fac..c869cb7a3 100644 --- a/server.js +++ b/server.js @@ -5,15 +5,19 @@ var mongoose = require('mongoose'); // mongoose for mongodb var port = process.env.PORT || 8080; // set the port var database = require('./config/database'); // load the database config +var morgan = require('morgan'); // log requests to the console (express4) +var bodyParser = require('body-parser'); // pull information from HTML POST (express4) +var methodOverride = require('method-override'); // simulate DELETE and PUT (express4) + // configuration =============================================================== mongoose.connect(database.url); // connect to mongoDB database on modulus.io -app.configure(function() { - app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users - app.use(express.logger('dev')); // log every request to the console - app.use(express.bodyParser()); // pull information from html in POST - app.use(express.methodOverride()); // simulate DELETE and PUT -}); +app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users +app.use(morgan('dev')); // log every request to the console +app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded +app.use(bodyParser.json()); // parse application/json +app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json +app.use(methodOverride()); // routes ====================================================================== require('./app/routes.js')(app);