I'm noob on nodejs and i'm trying some tutorials of nodejs. I'm trying this tutorial: http://cestfait.ch/content/chat-webapp-nodejs it works wonderful on my localhost but not when I upload to appfog like you can see here: http://nodebruno.hp.af.cm/
For example, the prompt don't show up. I changed the code to avoid the prompt and insert the nickname on a input text and this work on localhost but doesn't work on appfog too.
I already tried on nodejitsu servers and I have the same problem
Can you help me ?
Your app has an error, it's trying to connect to a localhost socket.io server.
You need to change this line:
var socket = io.connect('http://localhost:8000');
to
var socket = io.connect();
And it would work preferably on Nodejitsu
Related
I have a website running on Node built from ReactJS and I want to have an option to send a file to an SSH remote server by entering IP, username and password.
I have been looking at large number of options but kept getting errors. I tried npm i ssh2 and node-ssh but both doesn't seem to be working well with React..
The simplest thing I tried was building a fresh website using npx create-react-app and adding node-ssh to it. I then tried adding the simple line of code
const { NodeSSH } = require('node-ssh');
const ssh = new NodeSSH();
But I kept getting these errors and after a lot of digging it seems like this is not the right way of approaching this.
This is why I need your help.. I believe there has to be a way to access SSH server from a node webserver..
Thank you
I'd like to run a p2p chat written in node js with socket io on GAE.
My app works locally fine but I get error messages when I run it on the GAE servers related to the socket io I think.
Here are the two relevant script tags of my local client.html when running locally:
<script src="/socket.io/socket.io.js"></script>
<!-- <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script> -->
<script type="text/javascript">
// our socket.io code goes here
var socketio = io.connect("127.0.0.1:1337");
socketio.on("message_to_client", function (data) {
to_history(data['message']);
});
function send_message() {
var msg = [document.getElementById("text1").value, user1, uuid];
socketio.emit("message_to_server", {
message: msg
});
}
</script>
I've seen blogs/posts saying that for deployment I need to allow a firewall rule here on SO (which is in place now). I also tried pointing my deployed app to a static external IP like (after making it static in my google cloud console):
var socketio = io.connect('https://104.197.51.XXX')
or to point it to the port 65080 specified in my firewall rule (see documentation by google here:
var socketio = io.connect('https://104.197.51.XXX:65080')
None of this works.
I have the html loaded fine and the jQuery part I have and css is also loading just fine. It's just the socket stuff that I seem to be getting wrong. What do I have to change?
If this is of use, here the app.yaml:
runtime: nodejs
vm: true
Any help is greatly appreciated. Thanks.
Sadly, App Engine just doesn't support websockets (yet). The hack-around you're using is really unreliable for a few reasons:
it makes a direct connection to the instance, which can go down or be recycled at any time
Short of magic hackery, there's really no way to get https going down this route.
In short - this is not production ready. That having been said....
https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/appengine/websockets
That link will show you a working example and instructions of how to set it up.
Instead of that - I'd suggest using pubnub:
https://www.pubnub.com/docs/nodejs-javascript/pubnub-javascript-sdk
It has a really nice API, and is going to be way more reliable than anything you can hack together with App Engine (you know, until we fix this). You can see a few examples that I've done here:
https://github.com/JustinBeckwith/cloudcats/blob/master/web/public/script.js
https://github.com/JustinBeckwith/hatspin/blob/master/public/script.js
I hope this helps!
I also made the similar chat webapp recently and deployed it on heroku (https://chatterboxxx.herokuapp.com). I also used socket.io for this. I am not sure of GAE, but I don't think you need to specify any IP address in your socket.io js code.
I think you should use
var socketio = io();
instead of
var socketio = io.connect("127.0.0.1:1337");
This works well for me.
I'm new at nodejs and I gues therefor I can't get to it.
I'm trying to install https://github.com/mongo-express/mongo-express as middleware (I got it to work as standalone app).
I did those three steps
var mongo_express = require('mongo-express/lib/middleware')
var mongo_express_config = require('./mongo_express_config')
app.use('/mongo_express', mongo_express(mongo_express_config))
And after that not sure how to reach it(how do I run it). I hoped for the port 8081 to be active but it's not.
Can anyone help me and explain how this supposed to work?
this is my first node.js and socket.io application , i didn't use express ,I want to deploy the application on heroku do i need to use it ? i mean i just did npm install socket.io on localhost and in my server file i.e game.js i have io = require("socket.io") and socket = io.listen(Number(process.env.PORT)) only and in one of the files where from where i am sending the message i have socket = io.connect();
so please tell me if i need to use express and how show i modify my existing application ?
I have given the link to the source of application
( https://github.com/bitgeeky/herokutest )
Although the Application works fine on localhost by changing the port no , to some port no like (8000) but Heroku error log on doing "heroku open" is http://pastebin.com/MtB0z5vQ
I noticed that you haven't created a http server. I am assuming that you are creating a web application, since you are deploying to heroku. For that, you need to create a http server in nodejs.
Go through socket.io https://github.com/LearnBoost/socket.io
Also http://socket.io/#how-to-use
This should get you started
Note: You do not need express. But it will make your work easier in many ways. Depends on the type of application that you want to create.
I am building windows azure application which is primarily based on .NET, but I also have to build a socket.io server using node.js hence i need to deploy a socket.io server and use this socket.io url to connect in my .NET application.
I followed all the steps listed here . And I am able to get the socket.io running on my local but when i deploy to cloud, it doesnt start. Please find below a code snippet for socket.io
var app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server, { origins: '*:*' });
server.listen(4001);
When i hosted it in my local emulator, 127.0.0.1:81 was pointing to this in my browser
But 127.0.0.1:4001 showed "Cannot GET /" on the browser, which is an indicative that the socket.io server is running on that url.
But when i deploy the same to cloud, i get the same as the screenshot on the url where the cloud service is hosted but on port 4001 where the socket.io server should have started it says page cannot be displayed.
Please let me know if you need to see any other files like web.config etc.
I have been stuck on this issue from forever and its really crucial for my project, any suggestions or ideas would be deeply appreciated.
Thanks
The important part that you are missing from the sample is setting of the port number
var port = process.env.port || 1337;
and
.listen(port)
when you are running inside of the Azure environment (even emulated) the ports are assigned for you, the port environment variable will tell you where. 4001 is likely not the assigned port.
The 1337 would only be used if you are running by executing
node server.js
from the command line