README.md (2117B)
1 2 # socket.io-client 3 4 [![Build Status](https://secure.travis-ci.org/socketio/socket.io-client.svg?branch=master)](http://travis-ci.org/socketio/socket.io-client) 5 [![Dependency Status](https://david-dm.org/socketio/socket.io-client.svg)](https://david-dm.org/socketio/socket.io-client) 6 [![devDependency Status](https://david-dm.org/socketio/socket.io-client/dev-status.svg)](https://david-dm.org/socketio/socket.io-client#info=devDependencies) 7 [![NPM version](https://badge.fury.io/js/socket.io-client.svg)](https://www.npmjs.com/package/socket.io-client) 8 ![Downloads](http://img.shields.io/npm/dm/socket.io-client.svg?style=flat) 9 [![](http://slack.socket.io/badge.svg?)](http://slack.socket.io) 10 11 [![Sauce Test Status](https://saucelabs.com/browser-matrix/socket.svg)](https://saucelabs.com/u/socket) 12 13 ## How to use 14 15 A standalone build of `socket.io-client` is exposed automatically by the 16 socket.io server as `/socket.io/socket.io.js`. Alternatively you can 17 serve the file `socket.io.js` found in the `dist` folder or include it via [CDN](https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js). 18 19 ```html 20 <script src="/socket.io/socket.io.js"></script> 21 <script> 22 var socket = io('http://localhost'); 23 socket.on('connect', function(){}); 24 socket.on('event', function(data){}); 25 socket.on('disconnect', function(){}); 26 </script> 27 ``` 28 29 ```js 30 // with ES6 import 31 import io from 'socket.io-client'; 32 33 const socket = io('http://localhost'); 34 ``` 35 36 A slim build (without `JSON3`, a JSON polyfill for IE6/IE7, and `debug`) is also available: `socket.io.slim.js`. 37 38 Socket.IO is compatible with [browserify](http://browserify.org/) and [webpack](https://webpack.js.org/) (see example [there](https://github.com/socketio/socket.io/tree/2.0.3/examples/webpack-build)). 39 40 ### Node.JS (server-side usage) 41 42 Add `socket.io-client` to your `package.json` and then: 43 44 ```js 45 var socket = require('socket.io-client')('http://localhost'); 46 socket.on('connect', function(){}); 47 socket.on('event', function(data){}); 48 socket.on('disconnect', function(){}); 49 ``` 50 51 ## API 52 53 See [API](/docs/API.md) 54 55 ## License 56 57 [MIT](/LICENSE)