Skip to content

Commit fc3c842

Browse files
committed
eslint
1 parent 0aba938 commit fc3c842

24 files changed

+259
-212
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
// Example 1
24
setTimeout(function () {
35
console.log('world')
@@ -6,22 +8,22 @@ console.log('hello')
68

79
// Example 2
810
require('fs').readFile('difference-node.js', function (err, data) {
9-
if (err) throw err
11+
if (err) throw err
1012
console.log(data.toString())
1113
})
1214

1315
// Example 3
1416
require('fs').readFile('difference-node.js', function (err, data) {
15-
if (err) throw err
17+
if (err) throw err
1618
console.log('one:', data.toString())
1719
})
1820
require('fs').readFile('difference-php.php', function (err, data) {
19-
if (err) throw err
21+
if (err) throw err
2022
console.log('two:', data.toString())
2123
})
2224

2325
// Example 4
2426
require('http').createServer(function (req, res) {
25-
res.writeHead(200, {'Content-Type': 'text/plain'})
27+
res.writeHead(200, { 'Content-Type': 'text/plain' })
2628
res.end('Hello World\n')
2729
}).listen(8000, '127.0.0.1')
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
{
2-
"name": "my-program",
3-
"version": "1.0.0",
4-
"description": "program description",
5-
"homepage": "http://programs-website.com",
6-
"keywords": [
7-
"one",
8-
"two",
9-
"three"
10-
],
11-
"author": "Bevry Pty Ltd <us@bevry.me> (http://bevry.me)",
12-
"maintainers": [
13-
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)"
14-
],
15-
"contributors": [
16-
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)"
17-
],
18-
"bugs": {
19-
"url": "http://programs-issue-tracker.com"
20-
},
21-
"repository" : {
22-
"type": "git",
23-
"url": "http://programs-repository.git"
24-
},
25-
"engines" : {
26-
"node": ">=0.6.0",
27-
"npm": ">=1.1.0"
28-
},
29-
"dependencies": {
30-
"connect": "2.6.x",
31-
"express": "3.0.x",
32-
"socket.io": "0.9.x"
33-
},
34-
"devDependencies": {
35-
"coffee-script": "1.4.x"
36-
},
37-
"directories": {
38-
"lib": "./lib"
39-
},
40-
"bin": {
41-
"program": "./bin/program"
42-
},
43-
"scripts": {
44-
"test": "node ./test/everything.test.js"
45-
},
46-
"main": "./main.js"
47-
}
2+
"name": "my-program",
3+
"version": "1.0.0",
4+
"description": "program description",
5+
"homepage": "http://programs-website.com",
6+
"keywords": [
7+
"one",
8+
"two",
9+
"three"
10+
],
11+
"author": "Bevry Pty Ltd <us@bevry.me> (http://bevry.me)",
12+
"maintainers": [
13+
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)"
14+
],
15+
"contributors": [
16+
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)"
17+
],
18+
"bugs": {
19+
"url": "http://programs-issue-tracker.com"
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "http://programs-repository.git"
24+
},
25+
"engines": {
26+
"node": ">=0.6.0",
27+
"npm": ">=1.1.0"
28+
},
29+
"dependencies": {
30+
"connect": "2.6.x",
31+
"express": "3.0.x",
32+
"socket.io": "0.9.x"
33+
},
34+
"devDependencies": {
35+
"coffee-script": "1.4.x"
36+
},
37+
"directories": {
38+
"lib": "./lib"
39+
},
40+
"bin": {
41+
"program": "./bin/program"
42+
},
43+
"scripts": {
44+
"test": "node ./test/everything.test.js"
45+
},
46+
"main": "./main.js"
47+
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
var http = require('http')
2-
var count = 0
1+
'use strict'
2+
3+
const http = require('http')
4+
let count = 0
35
http.createServer(function (req, res) {
46
console.log('Received', ++count, 'requests so far')
5-
res.writeHead(200, {'Content-Type': 'text/plain'})
7+
res.writeHead(200, { 'Content-Type': 'text/plain' })
68
res.end('hello world\n')
79
}).listen(8000)
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1+
'use strict'
2+
13
// Application
2-
var net = require('net')
3-
var count = 0
4-
var sockets = {}
4+
const net = require('net')
5+
let count = 0
6+
const sockets = {}
57
function broadcast (message) {
6-
for ( var key in sockets ) {
7-
if ( sockets.hasOwnProperty(key) ) {
8-
sockets[key].write(message)
9-
}
10-
}
8+
for (const key in sockets) {
9+
if (sockets.hasOwnProperty(key)) {
10+
sockets[key].write(message)
11+
}
12+
}
1113
}
1214
net.createServer(function (socket) {
13-
sockets[socket.index = count++] = socket
14-
socket.write('Hello user ' + socket.index + '\n')
15-
broadcast('User ' + socket.index + ' joined\n')
15+
sockets[socket.index = count++] = socket
16+
socket.write('Hello user ' + socket.index + '\n')
17+
broadcast('User ' + socket.index + ' joined\n')
1618

1719
socket.on('data', function (data) {
18-
broadcast('User ' + socket.index + ' says: ' + data.toString())
20+
broadcast('User ' + socket.index + ' says: ' + data.toString())
1921
})
2022

2123
socket.on('end', function () {
2224
delete sockets[socket.index]
23-
broadcast('User ' + socket.index + ' left\n')
25+
broadcast('User ' + socket.index + ' left\n')
2426
})
2527
}).listen(8000)
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
'use strict'
2+
13
// Application
2-
var net = require('net')
3-
var sockets = []
4+
const net = require('net')
5+
let sockets = []
46
net.createServer(function (socket) {
5-
sockets.push(socket)
6-
socket.write('Talk to me.\n')
7+
sockets.push(socket)
8+
socket.write('Talk to me.\n')
79

810
socket.on('data', function (data) {
9-
for ( var i = 0; i < sockets.length; ++i ) {
10-
sockets[i].write(data)
11-
}
11+
for (let i = 0; i < sockets.length; ++i) {
12+
sockets[i].write(data)
13+
}
1214
})
1315

1416
socket.on('end', function () {
15-
var index = sockets.indexOf(socket)
17+
const index = sockets.indexOf(socket)
1618
sockets = sockets.slice(0, index).concat(sockets.slice(index + 1))
1719
})
1820
}).listen(8000)

node/handsonnode/~examples/03-server-simple/server-echo.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
var net = require('net')
1+
'use strict'
2+
3+
const net = require('net')
24
net.createServer(function (socket) {
35
socket.write('Talk to me.\n')
46
socket.on('data', function (data) {
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
var http = require('http')
1+
'use strict'
2+
3+
const http = require('http')
24
http.createServer(function (req, res) {
3-
res.writeHead(200, {'Content-Type': 'text/plain'})
5+
res.writeHead(200, { 'Content-Type': 'text/plain' })
46
res.write('hello\n')
57
setTimeout(function () {
68
res.end('world\n')
7-
}, 2*1000)
9+
}, 2 * 1000)
810
}).listen(8000)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
module.exports = {
24
staticPath: __dirname // process.cwd()
35
}

node/handsonnode/~examples/04-server-advanced/connect-static.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
'use strict'
2+
13
// Requires
2-
var connect = require('connect')
3-
var config = require('./config')
4+
const connect = require('connect')
5+
const config = require('./config')
46

57
// Server
6-
var app = connect()
7-
8+
const app = connect()
89

910
// Middlewares
1011

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
'use strict'
2+
13
// Requires
2-
var express = require('express')
4+
const express = require('express')
35

46
// Application
5-
var app = express()
7+
const app = express()
68

79
// Routes
810
// These make things easier
911
app.get('/', function (req, res) {
10-
res.send('hello world')
12+
res.send('hello world')
1113
})
1214

1315
// Fallback middleware
@@ -17,4 +19,4 @@ app.use(function (req, res) {
1719
})
1820

1921
// Server
20-
var server = app.listen(8000)
22+
const server = app.listen(8000)

0 commit comments

Comments
 (0)