Javascript News - A collection of audio articles aimed toward Full Stack Development with JS.

Making Full Stack Web Applications Real Time With Websockets


Listen Later

Hi and welcome to JavasScript News. Today I am talking about Websockets in Node.js. Specifically using WebSockets in a Full Stack environment: meaning one is sending messages from the server to client and the client to server in real-time. This means that one is able to display data as it happens and there is no need to auto-reload.

Some websocket libraries include the ws module, websocket library and socket.io. There is also the native javascript websocket interface that allows one to interact with websockets without a library in vanilla javascript.

Basically how one uses websockets in a full stack environment is by connecting the server to the client with socket.io. This is done by importing the socket.io module and then declaring a new io instance. After this is done one can connect to the socket by calling the socket variable. This was for the server. As for the client the socket.io-client library is used. This can be used in vanilla javascript with a script tag that imports socket.io-client or with react; vue or angular by importing with npm.

Basically how socket.io works is by enabling one to send a message from the server with the .emit method to the client with the .on method. This can be repeated from the client to the server in the same fashion.

Socket.io is a great library because it can also be compatible with databases to store the data. If one does not add a database the data will reset when the server does. In order to turn mongodb into a real-time database with websockets one is to use mongoose and the .watch() method.

Websockets are also compatible with the webrtc api enabling one to send buffer from the client to the server and visa-versa. This is the main technology between applications such as Skype and Zoom. Websockets are also compatible with GeoJSON in mongodb: allowing for one to be able to track runs and stuff.

In conclusion websockets are very helpful for the real-time usage of databases. The best library in npm for websockets is socket.io. This is the driving technology behind many applications today. Thank and best wishes upon your websockets journey.

---
This episode is sponsored by
· Anchor: The easiest way to make a podcast. https://anchor.fm/app
---
Send in a voice message: https://anchor.fm/javascript-news/message
Support this podcast: https://anchor.fm/javascript-news/support
...more
View all episodesView all episodes
Download on the App Store

Javascript News - A collection of audio articles aimed toward Full Stack Development with JS.By Javascript News