I am currently working on a server where I want to autorun a file whenever I connect to the server myself. Example; I start the server and when I connect to it I want it to run a backup. My server is running on another computer and I connect to it from my main computer to save performance. The thing is that I also want to be able to work inside the server from my main computer. Example; The server is running on PC1 and I want to have access to the server from PC2 via vagrant.
The server is run by vagrant.
I have some experience within - Ruby, C++, Vagrant, javascript and SQL if this is helpful for the answer.
I found how to connect to the server remotely via the vagrant environment using ssh vagrant#192.168.x.x where the x.x is the ip of the local computer.
Example
IP to the vagrant server is 192.168.192.192
On my main computer I run the command ssh vagrant#192.168.192.192 and I login with the default password.
Related
I have two electron apps. One is a server on machine1 and another is a client on machine2.
When I start the server from the electron app on machine1, I want machine2 (the client) to be able to be able to receive and send data to machine1 (the server).
I tried using http://localhost approach which works for the app during development but doesn't work for the packaged app which is installed on the machine.
Please help. Thanks
When you package an Electron app, it is no longer running on localhost, it runs on the IP address of the machine on which it is installed.
To establish communication between the server and client apps, you will need to use the IP address of the machine on which the server app is running. You can use the os module in Node.js to determine the IP address of the machine on which the server app is running. Once you have the IP address, you can use it to connect the client app to the server app.
You can also use a package like ip to get the IP address of the machine.
const ip = require('ip');
console.log(ip.address());
Hope this helps.
I am developing a react-admin site and using mongodb. When I uploaded files to the server, it seems that production version on server is using my local computer mongodb connection. This is my connection string: mongodb://localhost:27017/my-collection
If I try to access a site from my computer, it works, because it uses local computer connection, if I try to access it from phone , it does not works, only shows Could not connect to the server
Site is served by nginx and run with pm2
Can somebody help? What I am doing wrong?
I had to change url in react-admin dataProvider. it had localhost:3001, but I had to changed it to myDomain.com:3001
I have a node server with several node projects. I use nginx to get them all responding on port 80. Now, this works for the initial http request. For the websockets, I need to use the direct server port. To keep everything alive while developing I would like to try this, projects will have a dev and live version. Once de dev is stable, I will copy it to the live folder. The live folder is runned by a systemctl script where I define a difrent port to the live version so I can dev without taking the live down. The problem I encounter now is, how can I get the running server port in my client side Javascript so that the dev page connect to the dev port and visa versa?
currently I'm only using express, socket.io and mysql. I have no further npm packages installed. I searched allot but there is not to mush I can find. I found how to connect the socket to the page url but I cannot use that because that URL will always be on port 80. Further I found allot of huge packages that has no use for me since the original page is just static, the dynamics all run over websockets.
Is there any way to parse the port number in the clients .js file like I could do fairly easy in php? And if so, what would be the most efficient way. I could let javascript check if the page uses the live or dev URL but I would prefer not to hardcode my dev URL into JS where it is for everyone to see.
run a third node.js socket.io server program, all your clients connect to this server first.
In this simple node.js program, determine the type of clients by any means. e.g. different user id for dev/production users
send the server url and port to your client according to its type (dev or production)
you may also use this technique to separate your users to different production servers.
Last 2 days I spent more time and read 50+ articles and video to understand node.js and after installation now I can see the result in browser by http//:localhost:3000/ But I have confused in many case that I describe below.
I do all of my work in my share hosting server where I my keep my web site: www.myweb.com
In every article about node.js, they are teaching how to get a result by below code in a browser by http//:localhost:3000/ in local pc server.
test.js
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3000);
console.log('Server running at http://localhost:3000/');
But My Question:
If I use http//:www.myweb.com/test.js` in my browser, What will be the above code?
In case of local pc we write on npm node test.js, But In case of hosting server when any clint open the page like http//:www.myweb.com/test.js How to work it?
In case of php we used include ("head.php") to got something from that page But In this case How to make a call on node.js.
Well, what you need to do is understand how http web servers works.
Usually, on your remote machine (your server), you have an instance of a web server (ex : apache) running, which is listening to port 80 (standard port for http requests). It will handle every request made on that port, and manage routing to use the correct php/html file.
Then, it will run the php code server-side, to render an html file and serve it to the server. So the client will not see the php code at all.
Let's talk about Node.js. Node is an application that runs javascript code server-side, and can run an http server with using some modules. But the javascript code will never be shown to your client, he will only get the http response you send him (typically, the html page).
So now, with node.js, you need to do the same as the apache server did, by creating the http server. First, what you have to know is that not that many website host are offering node.js, or even console access. They usually serve the php/html files you put in the configured folder, and that's basically it. What you need is either a virtual machine, or a server on which you can install node.js and run it, or use a node.js hosting service, like heroku or nodejitsu to host your node.js http server.
So, to create the node.js http server, you need to create an http server (as you did in your code), and make it listen to port 80. Now, every http request send to your server will be handled by your node.js instance. Then, you can do anything you want with that request.
I hope I haven't been to messy.
You need to install NodeJS on the server. If this is shared hosting where you cannot install additional software then you will be unable to use NodeJS. In that case contact support of your web hosting company and inquire about NodeJS support.
On the other hand, if you do have root user or super user rights on a system, you can install NodeJS. For example for on CentOS/RHEL systems you can install using yum with the following commands.
sudo yum install epel-release
sudo yum install npm
For some of the other distributions of Linux: http://ask.xmodulo.com/install-node-js-linux.html
To access Node applications from your PC to the server, you also need to open a port in the server firewall that your Node aplication uses.
I'm building a chat system with websockets but a can't find how to keep runing the file that starts the websocket server. I'm using php, javascript and cpanel. Can anyone help me how to run the websocket server from cpanel and keep it runing like forever.
Thanks
you have to use ssh detail to connect your server from command prompt
ssh username#host-name