Skip to content

Commit cb5d82d

Browse files
committed
upgraded to latest versions of node, express, and angular
1 parent a550978 commit cb5d82d

File tree

14 files changed

+248
-550
lines changed

14 files changed

+248
-550
lines changed

.jshintrc

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
{
3+
"globals": {
4+
"esnext": true,
5+
"jasmine": false,
6+
"spyOn": false,
7+
"it": false,
8+
"console": false,
9+
"describe": false,
10+
"expect": false,
11+
"before": false,
12+
"after": false,
13+
"beforeEach": false,
14+
"afterEach": false,
15+
"waits": false,
16+
"waitsFor": false,
17+
"runs": false,
18+
"$": false,
19+
"confirm": false
20+
},
21+
"esnext": true,
22+
"node" : true,
23+
"browser" : true,
24+
"boss" : false,
25+
"curly": false,
26+
"debug": false,
27+
"devel": false,
28+
"eqeqeq": true,
29+
"evil": true,
30+
"forin": false,
31+
"immed": true,
32+
"laxbreak": false,
33+
"newcap": true,
34+
"noarg": true,
35+
"noempty": false,
36+
"nonew": false,
37+
"nomen": false,
38+
"onevar": true,
39+
"plusplus": false,
40+
"regexp": false,
41+
"undef": true,
42+
"sub": true,
43+
"strict": false,
44+
"white": true,
45+
"unused": false
46+
}

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2015 Michael Herman http://www.mherman.org/
3+
Copyright (c) 2016 Michael Herman http://www.mherman.org/
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

app.js

+30-28
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
1-
var express = require('express');
2-
var path = require('path');
3-
var favicon = require('serve-favicon');
4-
var logger = require('morgan');
5-
var cookieParser = require('cookie-parser');
6-
var bodyParser = require('body-parser');
1+
const express = require('express');
2+
const path = require('path');
3+
const favicon = require('serve-favicon');
4+
const logger = require('morgan');
5+
const cookieParser = require('cookie-parser');
6+
const bodyParser = require('body-parser');
77

8-
var routes = require('./server/routes/index');
8+
const routes = require('./server/routes/index');
9+
// var users = require('./routes/users');
910

10-
var app = express();
11+
const app = express();
1112

1213
// view engine setup
13-
app.set('views', path.join(__dirname, 'views'));
14-
app.set('view engine', 'jade');
14+
// app.set('views', path.join(__dirname, 'views'));
15+
// app.set('view engine', 'html');
1516

1617
// uncomment after placing your favicon in /public
17-
//app.use(favicon(__dirname + '/public/favicon.ico'));
18+
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
1819
app.use(logger('dev'));
1920
app.use(bodyParser.json());
2021
app.use(bodyParser.urlencoded({ extended: false }));
2122
app.use(cookieParser());
22-
app.use(express.static(path.join(__dirname, './client', 'public')));
23+
app.use(express.static(path.join(__dirname, 'client')));
2324

2425
app.use('/', routes);
26+
// app.use('/users', users);
2527

2628
// catch 404 and forward to error handler
27-
app.use(function(req, res, next) {
28-
var err = new Error('Not Found');
29-
err.status = 404;
30-
next(err);
29+
app.use((req, res, next) => {
30+
var err = new Error('Not Found');
31+
err.status = 404;
32+
next(err);
3133
});
3234

3335
// error handlers
3436

3537
// development error handler
3638
// will print stacktrace
3739
if (app.get('env') === 'development') {
38-
app.use(function(err, req, res, next) {
39-
res.status(err.status || 500);
40-
res.render('error', {
41-
message: err.message,
42-
error: err
43-
});
40+
app.use((err, req, res, next) => {
41+
res.status(err.status || 500);
42+
res.json({
43+
message: err.message,
44+
error: err
4445
});
46+
});
4547
}
4648

4749
// production error handler
4850
// no stacktraces leaked to user
49-
app.use(function(err, req, res, next) {
50-
res.status(err.status || 500);
51-
res.render('error', {
52-
message: err.message,
53-
error: {}
54-
});
51+
app.use((err, req, res, next) => {
52+
res.status(err.status || 500);
53+
res.json({
54+
message: err.message,
55+
error: {}
56+
});
5557
});
5658

5759

bin/www

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
var app = require('../app');
8-
var debug = require('debug')('todo-node-postgres:server');
8+
var debug = require('debug')('node-postgres-todo:server');
99
var http = require('http');
1010

1111
/**
@@ -60,7 +60,7 @@ function onError(error) {
6060

6161
var bind = typeof port === 'string'
6262
? 'Pipe ' + port
63-
: 'Port ' + port
63+
: 'Port ' + port;
6464

6565
// handle specific listen errors with friendly messages
6666
switch (error.code) {

client/javascripts/app.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
angular.module('nodeTodo', [])
2+
.controller('mainController', ($scope, $http) => {
3+
$scope.formData = {};
4+
$scope.todoData = {};
5+
// Get all todos
6+
$http.get('/api/v1/todos')
7+
.success((data) => {
8+
$scope.todoData = data;
9+
console.log(data);
10+
})
11+
.error((error) => {
12+
console.log('Error: ' + error);
13+
});
14+
// Create a new todo
15+
$scope.createTodo = () => {
16+
$http.post('/api/v1/todos', $scope.formData)
17+
.success((data) => {
18+
$scope.formData = {};
19+
$scope.todoData = data;
20+
console.log(data);
21+
})
22+
.error((error) => {
23+
console.log('Error: ' + error);
24+
});
25+
};
26+
// Delete a todo
27+
$scope.deleteTodo = (todoID) => {
28+
$http.delete('/api/v1/todos/' + todoID)
29+
.success((data) => {
30+
$scope.todoData = data;
31+
console.log(data);
32+
})
33+
.error((data) => {
34+
console.log('Error: ' + data);
35+
});
36+
};
37+
});

client/public/javascripts/app.js

-47
This file was deleted.

client/public/stylesheets/style.css renamed to client/stylesheets/style.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ ul {
2020

2121
.header {
2222
text-align: center;
23-
}
23+
}

client/views/index.html

+7-16
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
<head>
44
<title>Todo App - with Node + Express + Angular + PostgreSQL</title>
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<!-- styles -->
7-
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
8-
<link href="stylesheets/style.css" rel="stylesheet" media="screen">
6+
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" media="screen">
7+
<link rel="stylesheet" href="/stylesheets/style.css" media="screen">
98
</head>
109
<body ng-controller="mainController">
11-
1210
<div class="container">
13-
1411
<div class="header">
1512
<h1>Todo App</h1>
1613
<hr>
1714
<h1 class="lead">Node + Express + Angular + PostgreSQL</h1>
1815
</div>
19-
2016
<div class="todo-form">
2117
<form>
2218
<div class="form-group">
@@ -25,21 +21,16 @@ <h1 class="lead">Node + Express + Angular + PostgreSQL</h1>
2521
<button type="submit" class="btn btn-primary btn-lg btn-block" ng-click="createTodo()">Add Todo</button>
2622
</form>
2723
</div>
28-
2924
<br>
30-
3125
<div class="todo-list">
3226
<ul ng-repeat="todo in todoData">
33-
<li><h3><input class="lead" type="checkbox" ng-click="deleteTodo(todo.id)">&nbsp;{{ todo.text }}</li></h3><hr>
27+
<li><h3><input class="lead" type="checkbox" ng-click="deleteTodo(todo.id)">&nbsp;{{ todo.text }}</h3></li><hr>
3428
</ul>
3529
</div>
36-
3730
</div>
38-
39-
<!-- scripts -->
40-
<script src="http://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script>
41-
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js" type="text/javascript"></script>
42-
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.12/angular.min.js"></script>
31+
<script src="//code.jquery.com/jquery-2.2.4.min.js" type="text/javascript"></script>
32+
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
33+
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.6/angular.min.js"></script>
4334
<script src="javascripts/app.js"></script>
4435
</body>
45-
</html>
36+
</html>

config.js

-3
This file was deleted.

package.json

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
{
2-
"name": "todo-node-postgres",
2+
"name": "node-postgres-todo",
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
66
"start": "supervisor ./bin/www"
77
},
88
"dependencies": {
9-
"body-parser": "~1.10.2",
10-
"cookie-parser": "~1.3.3",
11-
"debug": "~2.1.1",
12-
"express": "~4.11.1",
13-
"jade": "~1.9.1",
14-
"morgan": "~1.5.1",
15-
"pg": "^4.2.0",
16-
"serve-favicon": "~2.2.0"
17-
},
18-
"devDependencies": {
19-
"supervisor": "~0.7.1"
9+
"body-parser": "~1.15.1",
10+
"cookie-parser": "~1.4.3",
11+
"debug": "~2.2.0",
12+
"express": "~4.13.4",
13+
"jade": "~1.11.0",
14+
"morgan": "~1.7.0",
15+
"pg": "^6.1.0",
16+
"serve-favicon": "~2.3.0"
2017
}
2118
}

server/models/database.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var pg = require('pg');
2-
var path = require('path');
3-
var connectionString = require(path.join(__dirname, '../', '../', 'config'));
1+
const pg = require('pg');
2+
const connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/todo';
43

5-
var client = new pg.Client(connectionString);
4+
const client = new pg.Client(connectionString);
65
client.connect();
7-
var query = client.query('CREATE TABLE items(id SERIAL PRIMARY KEY, text VARCHAR(40) not null, complete BOOLEAN)');
8-
query.on('end', function() { client.end(); });
6+
const query = client.query(
7+
'CREATE TABLE items(id SERIAL PRIMARY KEY, text VARCHAR(40) not null, complete BOOLEAN)');
8+
query.on('end', () => { client.end(); });

0 commit comments

Comments
 (0)