do i need to install WebSockets library for node? - node.js

I'm reading a book on using node.js for creating real time games.the problem is,it was published on 2011 with older version of node
for example it says :
Next, we will install the WebSockets library for the Node.JS server.
is it still necessary to do this right now with node-v0.12.0 ?

NodeJS does not have a built-in websockets library as of v0.12.0. There are many plugins available, socket.io being one that is currently popular and IMO easy to use (express.io, which combines socket.io + express, is another one I use often when I want to mix http and ws protocols in a single app).
So the answer is: if you want websockets, then yes, you'll have to install something, and it's probably best to use the package / plugin / library that the book tells you too otherwise their code samples might not work (they might not work anyway, unless you go back and get the exact version(s) specified in the book.)

Related

How to use Telegram's TDlib with Node.js

There is TDlib which allows to work with Telegram Client API.
Documentation says that it's possible to use it with almost any language.
I can't imagine myself how I can use it with Node.js
Could you tell me where to start from or provide me with a sample code?
You can make requests and get updates using td_json_client and node-ffi interfaces. Official repository provides a simple example.
If you don't want to create API client from zero, you may use one of exists. For example, check out Airgram. This is a strong typed tdlib client for NodeJS.
You can probably port one of the examples on their GitHub repos (Python can be an easy one). You needs to learn how to use binary modules with node.
Or you can check one of the 3rd party libraries (eg. https://github.com/k-egor-smirnov/node-tg-native)
There are 2 active TDLib wrappers in Node.js:
https://github.com/airgram/airgram
https://github.com/Bannerets/tdl
Both require you to build the TDLib binary yourself before using these wrapper: https://tdlib.github.io/td/build.html

is it possible to make chat app in node without using socket.io

I want to make small chat app in nodejs.
But every where i found that to achieve this functionality node is used with socket.io
As node was also created with push notification in mind so thinking
How to create chat app purely in node if possible ?
Thanks!
I want to make small chat app in nodejs. But every where i found that
to achieve this functionality node is used with socket.io. As node
was also created with push notification in mind so thinking How to
create chat app purely in node if possible ?
Yes, it is possible to create a node.js application that supports chat without using socket.io. You have these choices:
Use a straight webSocket to "push" to the client. You will need to find or write your own server-side code for handling the webSocket protocol because such code is not built into node by default. The ws module is one such library. If using a plain webSocket, you will likely have to implement on your own some of the functionality that socket.io implements such as auto-reconnect.
Find some other library (besides socket.io) that is built on top of a webSocket that would let you push data to a client.
Invent your own substitute for a webSocket (probably client polling or long polling) and code that. This is what was done before webSockets existed. It is much less efficient than a continuously connected webSocket.
All of these choices involve writing some code that has already been written for you in socket.io so most developers would rather just use the already working and already tested solution rather than reimplement it themselves.
To get into further detail in your question, you will need to define what "purely in node" means to really answer this question. That's not a well defined term. The socket.io library is just a library written in Javascript just like thousands of other libraries you can use in node.js to get your job done.
As you quickly see with node programming, you can't do very much at all in a default node instance without loading other libaries. Some of these libraries come with a default installation of node (like the fs library or http library, for example) and others are libraries that you install before using (usually as simple as typing "npm install socket.io") and then var io = require("socket.io");.
If you are not going to use the socket.io library, then you need a mechanism for "pushing" data to a client in order to make a chat application work. The only true "push" that has any cross-browser support is a webSocket. A webSocket is what socket.io uses. You could use a webSocket from node without using socket.io, but you'd have to write or find code that implements the webSocket protocol that you can run on node (the ws module is one such library). Such code is not built into node by default.
If you weren't going to use webSocket, then there is no other cross-browser method to "push" data to a browser client. Your only other alternative I'm aware of would be browser polling which isn't actual push, but tries to simulate push by just regularly asking the server if the server has anything new for a particular client. An enhancement to straight polling is "long polling" which was invented before we had actual push with webSockets.
All of this problem has already been solved in socket.io so unless you really just want your own research project to rebuilt similar functionality in your own code, you may as well build on solutions that have already been done by using something like the socket.io library.
If you have some specific objection to the socket.io library, then please explain that objection so we can understand what your real goal is here.
Node.js doesn't come with an out-of-the-box server-side Websocket implementation, so you will have to, at least, introduce a package which does.
If you don't want to go with socket.io, you can then defer to ws, which is what socket.io uses under the hood.

AS3 library for Socket.io

I'm using node.js+socket.io in my projects, and one of the issues that bothers me the most is absence of normal AS3 library than can handle communications between as3 and node.js using socket.io.
In my last project, I used https://github.com/simb/FlashSocket.IO this library, but I had to roll back to node.js v0.8.25.
So - requirements:
Works with node.js v0.10.x
Works with socket.io v0.9.x
Secure connection support (wss)
It would be nice to have more than one library, maybe someone knows a better one?
Thanks!
I also needed this, so here's what I used: https://github.com/sinnus/socket.io-flash.
requires Socket.IO(>= v.0.8)

NodeJS using redis - installing with hiredis vs without?

I'm integrating redis into my NodeJS server app, and I'm trying to figure out whether or not to install node_redis with the hiredis command. I assume that the option to install it wouldn't have been made available if it wasn't useful in some way or another. At the same time, the github page for node_redis (https://github.com/mranney/node_redis) makes it clear that upgrading to newer versions of nodeJS can cause problems with the hiredis option added.
Could somebody lay out the unwritten pros and cons of adding the hiredis vs not? How much of a performance increase is there in going with the C library?
For production I would seriously consider using hiredis parser because it performs better. For testing you do not need it. Then when you deploy new version to the server you just recompile hiredis. That is not such a big deal. Also when you have proper tests in play you would notice when something is wrong with redis/hiredis(or any place else).

Easiest way to work with WebSockets in Node.js

I want to work with WebSockets in Node.js web app, and I am looking for the easiest way to do this. I've seen so many github repositories seemingly providing some ease of use.
But, I'm just looking to see if there's one that stands out as having the most support, or most widely implemented.
I was kind of leaning towards Socket.IO but I'm not entirely sure.
Any advice?
Thanks!
use now now or socket.io.
now is an abstraction build on socket.io which allows you to define methods on a shared object across client and server. This means you dont have to interact with the stream manually and can just seemingly call methods. Do read their best practices before use though.
now also has a grouping system in build which means you can talk to clients in groups rather then one or all.
socket.io itself is recommended because of it's excellent browser support with its range of fallbacks. It's also owned/maintained by a node.js startup so it's more likely to be maintained in the future. And it also has a range of server-side socket.io implementations for platforms other then node.js so you can use the same API on multiple platforms.
If you find socket.IO too large or bloated you can go for the lightweight websocket-server. This is just a simple websocket implementation and is reasonably stable. I have personally used this if I want something which is a very minimal abstraction and if I want more low level access to the websocket server itself.
Take a look at this blog post, it's very informative...

Resources