I am creating a Node.js app on Heroku and have run into an issue. I am trying to use Hook.io in my application but am getting a "Bad Bind" error from Heroku because Hook uses port 5000. Does anyone know of a way around this, maybe by somehow telling Heroku I need another port for Hook?
What you describe requires hook.io have access to bind to multiple TCP ports. I'm not sure how much success you will find on Heroku with this.
You'll also note that hook.io-webserver has been deprecated see: https://github.com/hookio/webserver in favor of the latest core hook.io API which allows for native HTTP and Websocket support for hooks.
For new HTTP webserver API, see: https://github.com/hookio/hook.io/blob/master/examples/webserver/server.js
Hook.io is defaulting to port 5000, but on Heroku, you need to use the port Heroku dynamically assigns your app.
var hook = hookio.createHook({
hook-port: process.env.PORT || 5000
});
Here are the configs available for Hook.io.
Related
I am trying to deploy a frontend react application with a django backend. I am able to get Heroku's PORT environment variable just fine for the Django backend, but no matter what I do or try, process.env.PORT keeps returning undefined. I have tried adding a temporary variable that begins with REACT_APP that just reads the PORT variable in the procfile. Env files won't work because the PORT variable is dynamically allocated.
Every resource I have found have said to either try a .env file or exporting the variable, but like I said, that is unrealistic because Heroku dynamically allocates the port. Any ideas?
Environment variables aren't available in the client. That's running in the user's browser, not the server. For that matter there isn't a Node process running on the server, either. Given you're using an NGINX buildpack the Django app is presumably in a different dyno entirely, you don't need to know which PORT it's bound to. - #jonrsharpe
In the Heroku deployed environment, the project should be oriented such that the frontend will make a request to the backend through a specific url configuration, not through a different port call.
I'm trying to set up a reverse proxy on the development server for my VUE js webapp to get around the CORS issue that I was getting when I was trying to use my flask HTTP APIs with the vue js webapp.
I did this by creating a vue.config.js file in the root of the project directory:
module.exports = {
devServer: {
proxy: 'http://localhost:5001/'
}
}
when I run npm run serve, and try to use a REST API defined on port 5001 - I don't see the request going to port 5001, it uses the same port as the web app.
And there are no useful logs being written to stdout either to help me debug this.
Has anyone come across this issue before ?
I had a similar issue and found that the port was already in use by another application and hence it was not going to the correct port. Once i shutdown the other app, it started working as expected.
I have a slight problem with use of Node.js and socket.io on Heroku. It works fine locally but as soon as I push it to Heroku and go on the website it gives me the application error page. Looking at the logs there is no explicit error but I have a feeling what it might be. When I run it locally, I use sudo node server to start the app. Just node server gives the same effect as that on heroku.
So basically, my question is: How do I get Heroku to run in sudo mode, or how can I remove the need to use sudo altogether?
Apologies as this is my first time using socket.io, so I am a bit unfamiliar with the workings of the library.
P.S. I am using Express 3.
I would check into the port you are using. On a normal ubuntu machine for example you may have to use sudo for low numbered ports (such as port 80). Besides that Heroku has a lot of load balancing going on, so the port you will use to connect to the service may not be the same as the port you tell the instance to listen on.
I would try using port 5000 as per this example from Heroku
Nodejs with sockets
I have this web app written with express and socket.io using node.js, the app works brillantly on localhost, but when i push to my ec2 server, it connects for like 20 seconds then disconnects, and then connects again etc...
giving me the error on the node console as
warn - websocket connection invalid
info - transport end
SERVER
app = express()
server = http.createServer(app)
io = require('socket.io').listen(server)
CLIENT
socket = io.connect()
I know the problem is not with my code, because I fully tested the web app on localhost, so the only problem is where this code is running, which is my ec2 instance?
There could be many possible reasons you can get this error:
You are using browser that partially or does not support websockets. You can check if your browser supports websockets here.
Using proxy that does not support websocket. If there is some server(load balancer) between your client and your node server that does not support websocket.
You are using socket.io version 0.9.1/0.9.1-1. This behaviour is a reported bug for this version. So upgrade to latest socket.io version which is 0.9.14.
Browser connectivity is firewalled/blocked.
Code related problem.
Make sure you're using latest versions of node, express and socket.io on your ec2. Also, provide some data about currently used versions both on your local machine and on ec2 instance.
Running on your local machine you don't have to deal with network latency, NAT issues, or firewalls. Running on EC2 you have all of those.
Web Sockets are relatively new and unstable. So to begin with be sure you're running the latest versions (and let us know what they are). Perhaps the version of socket.io installed on your local machine is different than the version installed in your EC2 server.
If there is no activity during those 20 seconds before losing the connection, one possibility is that keep-alive is set too low.
See https://groups.google.com/forum/?fromgroups=#!topic/socket_io/RUv70BguZ-U for a similar problem. The solution there was to use heartbeat to keep the connection open.
A bit more on socket.io heartbeats if you're not already using them:
Advantage/disadvantage of using socketio heartbeats
I'd like to enable socket-based p2p communications between two or more different node.js application servers. I'm using socket.io to handle all such communication between a given server and the web application it serves - but what I'm looking for is a way to communicate server-to-server.
I had initially assumed it would be as easy as something like this:
var io = require("socket.io");
var socket = io.connect("my remote endpoint");
However, as it turns out the server-side socket.io implementation doesn't offer a "connect" method, only a listen method.
Why is this? Why can't I treat a node application server as a client to a socket.io server running elsewhere? Is there any way that I can achieve this functionality?
OK, so thanks to #pimvdb in the comments above I've got a workable solution.
Basically, the socket.io library that npm installs has a dependency on another module, called socket.io-client. In a standard socket.io installation this will be installed in node_modules/socket.io/node_modules/socket.io-client
However, it's also possible to say "npm install socket.io-client" and install it as its own first-class citizen library.
Then your usage looks like this:
var client = require("socket.io-client");
var socket = client.connect("http://myendpoint.com:3000/whatever");
socket.emit("test", "foo");
And everything works.
So, thanks man!
Just for clarification, this is an example with listeners and possibility to emit events (and without install again a module already installed)
var io = require('socket.io/node_modules/socket.io-client');
client = io.connect('http://'+CONFIG.host+':'+CONFIG.port);
client.on('connect',function() {
client.emit("test","foo");
});
Before you go full speed on socket.io for server-to-server communications.....
socket.io is engineered as a browser to server comm infrastructure. I'm far from certain it is the best solution for P2P server stuff. Plus, if you do server-to-server - why not just do Websockets? There are various websocket modules for node - e.g. https://github.com/einaros/ws