diff --git a/Readme.md b/Readme.md index 4f306c4e03..88e8b3aa52 100644 --- a/Readme.md +++ b/Readme.md @@ -55,10 +55,10 @@ Any serializable data structures can be emitted, including: Sample code: ```js -io.on('connection', function(socket){ - socket.emit('request', /* */); // emit an event to the socket - io.emit('broadcast', /* */); // emit an event to all connected sockets - socket.on('reply', function(){ /* */ }); // listen to the event +io.on('connection', socket => { + socket.emit('request', /* … */); // emit an event to the socket + io.emit('broadcast', /* … */); // emit an event to all connected sockets + socket.on('reply', () => { /* … */ }); // listen to the event }); ``` @@ -84,7 +84,7 @@ This is a useful feature to send notifications to a group of users, or to a give ## Installation ```bash -npm install socket.io --save +npm install socket.io ``` ## How to use @@ -93,11 +93,11 @@ The following example attaches socket.io to a plain Node.JS HTTP server listening on port `3000`. ```js -var server = require('http').createServer(); -var io = require('socket.io')(server); -io.on('connection', function(client){ - client.on('event', function(data){}); - client.on('disconnect', function(){}); +const server = require('http').createServer(); +const io = require('socket.io')(server); +io.on('connection', client => { + client.on('event', data => { /* … */ }); + client.on('disconnect', () => { /* … */ }); }); server.listen(3000); ``` @@ -105,8 +105,8 @@ server.listen(3000); ### Standalone ```js -var io = require('socket.io')(); -io.on('connection', function(client){}); +const io = require('socket.io')(); +io.on('connection', client => { ... }); io.listen(3000); ``` @@ -118,10 +118,10 @@ to pass the `Server` to `socket.io`, and not the express application function. Also make sure to call `.listen` on the `server`, not the `app`. ```js -var app = require('express')(); -var server = require('http').createServer(app); -var io = require('socket.io')(server); -io.on('connection', function(){ /* … */ }); +const app = require('express')(); +const server = require('http').createServer(app); +const io = require('socket.io')(server); +io.on('connection', () => { /* … */ }); server.listen(3000); ``` @@ -131,10 +131,10 @@ Like Express.JS, Koa works by exposing an application as a request handler function, but only by calling the `callback` method. ```js -var app = require('koa')(); -var server = require('http').createServer(app.callback()); -var io = require('socket.io')(server); -io.on('connection', function(){ /* … */ }); +const app = require('koa')(); +const server = require('http').createServer(app.callback()); +const io = require('socket.io')(server); +io.on('connection', () => { /* … */ }); server.listen(3000); ```