Search code examples
javascriptnode.jsexpresssocket.ioreal-time

Difference between express and socketio for nodejs


I am new to nodejs programming and going through various js that are being developed for node. My question is a basic one. Can someone please explain me the difference between express and socketio.

From what I know, express is a middleware on which we can use template engines like jade to push data to browser. What does socketio do then? Is it a transport layer? It is confusing to me to understand the difference and why we need express and socket in nodejs apps.


Solution

  • Express is an application server. You define routes and write code to generate your application's pages or API responses. It is basically a port of a ruby project called Sinatra. It works for a traditional request/response HTTP model.

    Socket.io is there to help you implement a server push model for real time type features such as alerts/notifications, chat, or whatever updates you want to do if you want them to just show up in the browser without waiting for the user to click a "refresh" button or anything like that.