How to browserify a Node.js WebSocket server? - javascript

Using examples from node-chromify I managed to run a Node.js Http server on a client side - inside a Chrome browser.
Then I tried to do exactly the same with a WebSocket server. Unfortunately I failed.
I think I tried most of the popular WebSocket libraries (npm modules) from Github.
While they work fine in configurations:
(a) both a WebSocket server and a WebSocket client are started from a Node command line
(b) the server runs from the command line and the client is included as a JavaScript in a html page (runs on a client side)
the scenario
(c) both the WebSocket server and the client running in a browser
is still unattainable for me so far.
During my attempts I tried the same approach by calling a command:
browserify server-ws.js -o bundle-server-ws.js
but when I included the generated bundle file into a html page I got always some critical errors regarding missing object definitions, etc.
In other words the above command seems not to bundle everything as the server code would expect during a runtime.
Should I use different switches/options during calling browserify?
Maybe it is not possible for browserify at all? For a client OK but with a server not...
I realize that migrating WebSocket stuff to the client side is much more complicated process than a regular npm module.
browserify v. 2.36.1
Node 0.10.22

Related

How do I debug server and client simultaneously in WebStorm?

I have a node.js app that runs a server and sends index.html. The index.html interacts with the server.
I want to debug the complete app, but when I debug the app, WebStorm only debugs the server.
Is this even possible in WebStorm? If not, are there other tools that can do this?
In the Node.js run configuration, Browser/Live Edit tab, specify the URL of your server, tick both After launch and with JavaScript debugger checkboxes - client-side debugger will be launched once you start your node server with this configuration, so that you will be able to debug both simultaneously, using a single run configuration.
See also https://www.jetbrains.com/help/webstorm/debugging-javascript-in-chrome.html#debugging_js_on_external_web_server for some hints on debugging client-side code run in browser

Applying node.js server to a web server

I am trying to learn how to use Node.js and web sockets to create simple multi-user interactive javascript programs. I used this tutorial series by Daniel Shiffman to create this example project. My next step would be to upload it, using WinSCP, to my RaspberryPi apache2 web server, but I haven't found a way to edit the code in a way to allow for that to work, and furthermore, I do not know what piece of the programs to execute to make it function properly.
Any assistance would be great. The extent of my Node / Socket.io knowledge comes entirely from the video series mentioned above, so you can assume I know almost nothing else.
Apache is a web server and it serves your file and send them to client for you, so when you have some client side things like html site with some css, javascript and images you can use apache to send them to client for you.
In node.js you can create this web server simply by following code and express library:
// Create the app
var app = express();
// Set up the server
var server = app.listen(3000, () => {
console.log('http server is ready')
});
as you created in your code too. by this web server you can host your files and do many more things like setup socket.io server and ... because you write web server yourself. with following code you serve static files in public directory (html, css, javascript and images ...):
app.use(express.static('public'));
after you finishing this process you can run it simply by:
npm install
node server.js
if you want you can run you code inside docker by creating Dockerfile and ...
About your question, you must move all your project files into raspberry and at the end you have following directory tree in somewhere in raspberry:
|- server.js
|- package.json
\ public
at this directory run above commands and your server will be up and running and you can access to it by http://raspberry_ip:3000.

WebSocket client can't connect to cloud server through corporate proxy except for web browsers! (ETIMEDOUT)

I'm trying to connect a WebSocket client (corporate Node.JS server) to a Cloud server, but it times out (connect ETIMEDOUT error).
I'm not sure which needs configuration... Linux, Node.JS or the WebSocket Client?
I've already configured the proxy for Linux (export proxy/https_proxy), and for Node.JS (npm config set proxy/https_proxy) but the problem persists!
I'm using the ws library found in https://npmjs.com and implemented it without any sort of options except setting port.
Any advice?
EDIT: Works fine in the web browser, by the way.
node does not automatically use any form of configuration for making HTTP requests through proxies -- ie, node does not read the PROXY or HTTPS_PROXY environment variables. npm config set proxy only affects npm itself.
In other words, node programs always try to access servers directly. It appears your network requires HTTP requests to go through a proxy, and direct connections are being silently dropped.
If you want your program to make HTTP requests through proxies, you must do so manually. The http-proxy-agent module can help you do this.

Run node.js app remotely on WebStorm?

I have node.js installed on Vagrant and WebStorm access to a project on shared folder via VirtualBox.
Can I run node.js application on WebStorm and see the output on WebStorm (Terminal or SSH)? At the moment I have to keep switching to Putty to run it to see the output, its gets quite tiring.
Running Node.js applications remotely is not currently supported, please follow WEB-6136 for updates.
Debugging remote applications is possible (using Node.js Remote Debug run configuration - see https://confluence.jetbrains.com/display/WI/Running+and+debugging+Node.js+application#RunninganddebuggingNode.jsapplication-DebuggingNode.jsappthatrunsremotely). But you can't see the remote process output in WebStorm console, as Stdout of it is not accessible via debug protocol WebStorm uses for remote debugging. Related feature request: WEB-17013
This feature is available through ssh on Webstorm 2017.1
Scroll down to Configuring a remote Node.js interpreter on a host accessible through SSH connection in the link below:
https://www.jetbrains.com/help/webstorm/configuring-node-js-interpreters.html

Socket.io on Heroku

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

Categories

Resources