I set up my Heroku instance to have Memcached, so now I have the MEMCACHE_PASSWORD, MEMCACHE_SERVERS and MEMCACHE_USERNAME env variables. How do I use them with any of the existing node.js memcached libraries? They all seem to take in just a host and port (I'm assuming the port is the default 11211?).
Thanks
As mentioned above, both Memcache addons on Heroku only support the binary protocol. I wrote a library, MemJS, that works with these addons (supports SASL with the binary protocol and recognizes the Heroku environment variables out of the box).
As of today, there is no Node library available that supports this scenario. Heroku's memcached instances use SASL for authentication. None of the currently available libraries support this, and there doesn't seem to be much momentum to add support, either.
If you want to try to implement this yourself, it might be worth taking a look at sasljs, which is a Node binding around GNU SASL. Your best bet would probably be to fork node-memcached and add SASL support there.
https://github.com/elbart/node-memcache
var client = new memcache.Client('11211', 'http://xxxx:xxxxx#mc10.ec2.northscale.net');
Related
I've made a node.js application which hosts a webserver over http using the express framework but i'd like to upgrade to https.
However I can't seem to find a good way to do this since the application will be run on different PCs which could have different public IP addresses so pre-generating a certificate wouldn't be possible.
Furthermore if possible I'd like to keep the application as portable as possible so locally installing open-ssl or expecting it is locally installed isn't really an option unless it can be packaged with the server itself somehow.
How would one go about building what I've described above?
If anyone could give me some pointers that would be fantastic.
Use docker/kubernetes together with a reverse proxy that automatically generates SSL certificates. I can recommend Traefik.
I want to purchase shared hosting with node js support. Can you provide us company name which support nodejs on shared server.
Thanks in advance.
You have many options out there. It depends on what you want to do but I would go for:
Heroku: It has a free option and it's compatible with integration testing tools like Travis. You can easily configure databases and also create environment variables easily
Glitch: It's also for free and you can just start programming because the server is already configured. I usually use this service when I want to try some small projects on node.js and I need a server to share what I'm doing.
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.)
Before starting to write my application I need to know what to do when a single node.js instance (express and (socket.io or nowjs)) isn't enough anymore.
You might tell me now, that I shouldn't care about scale until it's about time but I don't want to develop an application and run into trouble because you can't easily scale socket.io or nowjs across multiple instances.
I recently read that socket.io now supports a way to scale using Redis (which I also have no experience in). Nowjs is build on to of socket.io - does it work the same way? On nowjs.org you can read that a "distributed version of NowJS" is under development and is going to cost money.
If you need to scale node, the first place people usually start is putting a load balancer in front of multiple node instances. The standard for this today is nginx, though I would would like to check out the node balancer 'bouncy' that came out recently. Here's an example of someone using the nginx reverse proxy to manage multiple node instances:
Node.js + Nginx - What now?
The second thing you mention is socket.io/nowjs. Depending on how you're using these frameworks, you could get into a situation where you want to share context between clients who are hitting multiple node.js instances. If this is the case, I would recommend using a persistent store, like redis, to bridge the gap between your node instances. Here's an example:
How to reuse redis connection in socket.io?
Hopefully this is enough information and reading to get you started, let me know if you have any questions.
Happy coding!
Another useful link on 'Scaling Socket.IO' https://github.com/dshaw/talks/tree/master/2011-10-jsclub (slides and sample application)
Just as a sidenote on the discussion to use nginx for reverse proxy with socket.io, the way I understand it at least, nginx 1.0.x which is stable version does not support proxying of http/1.1 connections (which is needed in order to make socket.io work with websockets). there is a workaround described on here: http://www.letseehere.com/reverse-proxy-web-sockets to make it work, or use something like this: https://github.com/nodejitsu/node-http-proxy instead, the guys at nodejitsu says this should support it.
How do I use Memcache (on Heroku) from a Node.js service?
There is a Heroku article, explaining how to use Memcache from Ruby, Java and Python. I've asked this question on the Heroku mailing list with no results (my message seems to have been blocked or rejected).
MemJS looks like a good candidate.
MemJS is a pure Node.js client library for accessing the MemCachier service and other memcache servers. It uses the binary protocol and support SASL authentication.
You can follow the steps in the Heroku Ruby tutorial (http://devcenter.heroku.com/articles/memcache) to gain a basic understanding of how to interface with memcache on Heroku, but to do the same in node you should use the node-memcache library (https://github.com/elbart/node-memcache).
I hope this helps.
node-memcache will not work with any of the memcache providers on Heroku. In particular, the library uses the text protocol, rather than the binary protocol and doesn't support SASL authentication. MemJS does both (as Jacob pointed out)