Skip to content

Commit 98f7808

Browse files
Dan WahlinDan Wahlin
Dan Wahlin
authored and
Dan Wahlin
committed
Minor cleanup
1 parent e0e8065 commit 98f7808

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/lib/database.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ class Database {
1111
mongoose.connect(connectionString);
1212
connection = mongoose.connection;
1313
mongoose.Promise = global.Promise;
14-
mongoose.connection.on('open', () => {
14+
15+
mongoose.connection.on('error', (err) => {
16+
console.log('Error connecting to MongoDB: ' + err);
17+
callback(err, false);
18+
});
19+
20+
mongoose.connection.once('open', () => {
1521
console.log('We have connected to mongodb');
16-
callback();
22+
callback(null, true);
1723
});
1824

1925
}

src/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "angular2-nodejs-mongodb-customersservice",
2+
"name": "angular-nodejs-mongodb-customersservice",
33
"version": "1.0.0",
44
"repository": {
5-
"url": "https://github.com/DanWahlin/Angular2-NodeJS-MongoDB-CustomersService"
5+
"url": "https://github.com/DanWahlin/Angular-NodeJS-MongoDB-CustomersService"
66
},
77
"license": "MIT",
88
"scripts": {

src/server.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ class Server {
5252
app.use(cookieParser());
5353
app.use(csrf({ cookie: true }));
5454

55-
app.use(function (req, res, next) {
55+
app.use((req, res, next) => {
5656
var csrfToken = req.csrfToken();
5757
res.locals._csrf = csrfToken;
5858
res.cookie('XSRF-TOKEN', csrfToken);
5959
next();
6060
});
6161

62-
process.on('uncaughtException', function (err) {
62+
process.on('uncaughtException', (err) => {
6363
if (err) console.log(err, err.stack);
6464
});
6565
}
@@ -69,20 +69,20 @@ class Server {
6969
require("readline").createInterface({
7070
input: process.stdin,
7171
output: process.stdout
72-
}).on("SIGINT", function () {
72+
}).on("SIGINT", () => {
7373
console.log('SIGINT: Closing MongoDB connection');
7474
database.close();
7575
});
7676
}
7777

78-
process.on('SIGINT', function() {
78+
process.on('SIGINT', () => {
7979
console.log('SIGINT: Closing MongoDB connection');
8080
database.close();
8181
});
8282
}
8383

8484
initDbSeeder() {
85-
database.open(function() {
85+
database.open(() => {
8686
//Set NODE_ENV to 'development' and uncomment the following if to only run
8787
//the seeder when in dev mode
8888
//if (process.env.NODE_ENV === 'development') {
@@ -96,7 +96,7 @@ class Server {
9696
router.load(app, './controllers');
9797

9898
// redirect all others to the index (HTML5 history)
99-
app.all('/*', function(req, res) {
99+
app.all('/*', (req, res) => {
100100
res.sendFile(__dirname + '/public/index.html');
101101
});
102102
}

0 commit comments

Comments
 (0)