Skip to content

Guide · Open source

How to use Socket.IO: install and send messages

Updated · written with AI from the project's own documentation and checked against our catalogue data

Socket.IO is an open-source library that lets a server and a web or app client send messages to each other continuously, instead of the client repeatedly asking for updates. It is used for features such as live chat and live notifications. This guide covers what it is for, how to install it with npm, where to find the official documentation, and how to avoid common problems, so you know what to do next.

Socket.IOsocketio/socket.io · ★ 63.2k · MIT

Quick start

  1. 1Check prerequisites. Make sure Node.js is installed on the machine where you will run the server.
  2. 2Install the package. In your project folder, run npm install socket.io to add the package from npm.
  3. 3Open the documentation. Go to https://socket.io/docs/v4/ for the setup steps for server and client code.
  4. 4Write the server. Follow the official docs to create a server that accepts connections and sends messages.
  5. 5Write the client. Add the client code in your web or app front end so it connects to your server.
  6. 6Test two-way messages. Send a message from each side and confirm it arrives, then check the troubleshooting guide if it does not.

What Socket.IO is for

Socket.IO provides two-way, low-latency communication between a server and a client. Instead of the browser asking the server again and again whether anything has changed, the server can push messages to the client as soon as they happen.

It suits live chat, live notifications and other features where both sides need to send messages. It is written in TypeScript and released under the MIT licence.

  • Best for JavaScript or TypeScript developers building live chat or real-time notifications.
  • Best for teams already running Node.js on the server.
  • Useful when a project needs two-way messages between browser and server.
  • Probably not needed if you only need simple one-way updates or standard request-response APIs, where plain HTTP may be enough.

Install Socket.IO with npm

The main prerequisite is Node.js. Once it is available, install the package from npm using the command below, run in your project folder.

The README points to the official documentation for the rest of the setup, so check that page for how to create the server and client code.

npm install socket.io

Where to find the official documentation

The README is short and mostly points to the official documentation at socket.io, so that is the place to learn the full feature set and API. The README itself does not describe the detailed features, so do not rely on it alone.

For usage questions, the project asks people not to use the issues list, which is reserved for bug reports and feature requests. Use the documentation, the troubleshooting guide, Stack Overflow or GitHub Discussions instead.

  • Documentation: https://socket.io/docs/v4/
  • Troubleshooting guide: https://socket.io/docs/v4/troubleshooting-connection-issues/
  • Stack Overflow tag: socket.io
  • GitHub Discussions Q&A category for questions

Troubleshoot connection problems

If clients fail to connect or messages do not arrive, start with the project's troubleshooting guide for connection issues. It is the first place the maintainers point people to for usage problems.

If you believe you have found a bug, report it through the project's GitHub issues. For security vulnerabilities, do not open a public issue; follow the project's Security Policy instead.

Alternatives and how Socket.IO compares

Other projects in the same space include ws, uWebSockets.js, Primus and SockJS. This README does not compare them, so check each project's own documentation before choosing.

Socket.IO is a JavaScript and TypeScript option built around Node.js. The README does not describe support for other server languages, so if your server is not JavaScript, look at the alternatives and their documentation.

What people use it for

  • Live chat between users on a website
  • Live notifications pushed from server to browser
  • Two-way messaging between a browser front end and a Node.js back end

Frequently asked questions

Is Socket.IO free to use?

Yes. The project is released under the MIT licence, as stated in the README. Check the licence file in the repository for the full terms.

What do I need to install Socket.IO?

The README lists Node.js as the prerequisite. You install the package with npm install socket.io.

How do I install Socket.IO?

Run npm install socket.io in your project folder. The README gives this as the install command and points to the documentation for the rest of the setup.

What are the alternatives to Socket.IO?

The README lists ws, uWebSockets.js, Primus and SockJS as comparable projects. It does not compare them, so review each project's documentation.

Why is my Socket.IO connection not working?

Start with the official troubleshooting guide for connection issues at socket.io/docs/v4/troubleshooting-connection-issues/. Usage questions are best asked on Stack Overflow or GitHub Discussions, not the issues list.

Can I use Socket.IO with a server that is not JavaScript?

The README does not describe other server languages, so it does not confirm support for them. If your server is not written in JavaScript or TypeScript, check the official documentation or consider the alternatives.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Socket.IO is a good fit for JavaScript or TypeScript developers, especially Node.js teams, who need live chat or real-time notifications with two-way messages. If you only need one-way updates or ordinary request-response APIs, or your server is not JavaScript, a simpler HTTP approach or another tool may suit you better.

Install options & downloads