Installing Node Application on a server. Apache npm pm2 - node.js

I have installed a node js application (myapp.js) on a server with a particular IP.
I have npm installed and started the application
I have done this before but it was with apache and much more complex.
However this is the only application on this server. It is running fine.
Shouldn't this just be available at the ip it is installed on?
My own guess is it is something to do with the node setup within the application, as its referring to a local host 8050? Maybe this needs to be an IP?
Edit
I have just installed the application on the server. I havent set up any apache so maybe that is the issue. I think perhaps because i defined a port within the application it then needs a port specified on the server?

Your node application could be accessed locally from:
http://localhost:8050/
And from outside at:
http://youripaddress:8050/
Assuming that port 8050 is open, naturally.
You can also setup a reverse proxy with apache or nginx (or anything else) to proxy your application.

Related

How does a react app can be set up on server

I'm trying to understand what needs to be done to put my react app online.
Until now, I launched it on my mac using npm start, and accessing localhost:3000 or http://127.0.0.1:3000.
So I currently have bought a small server, installed everything (last version of node and npm, git and other necessary things), cloned my repo, and installed all dependencies.
When I do npm start on the server, it says it's available on port 3000. But when I go in my server's ip with the following :3000, it times out.
I don't really understand what need to be done to do this, I found some things about configuring apache on the server, others about using pm2 so have a node script running even after leaving the terminal, but that would be my next step I guess.. And other about configuring things with express (but do I need node+ express here ? As it's a simple front end react page ?).
if you are using webpack devserver, use it for development only
The tools in this guide are only meant for development, please avoid using them in production!
back to your question, there is a difference between binding to 127.0.0.1 or binding to 0.0.0.0
try changing the devserver to listen to 0.0.0.0
webpack.config.js
module.exports = {
//...
devServer: {
host: '0.0.0.0'
}
};
Usage via the CLI
webpack-dev-server --host 0.0.0.0
also note, that you will need to allow ingress rules (incoming connections). that is, allow a request from the internet to reach your server
There are a lot of configurations you will have to do when you deploy your application on a server. Building the app, Nginx, pm2 and even ssl certification. This video is 20min and has all you need. https://www.youtube.com/watch?v=oykl1Ih9pMg&t=1s

How can I run Laravel mix on custom URL?

I am creating one application that needs to be made on staging server from one point. Because creating it on local is impossible as it has some endpoints that other servers in network has to access.
I have created an application in Vue.js and Laravel. In local, I used to run npm run hot so that I don't have to re-compile when I change some code. But as I have to continue developing this application on a live server, I want to run npm run hot on a custom domain like staging.something.com instead of localhost:8080.
I don't have any issue if somehow localhost:8080 co-operates but when I run npm run hot on a live server, Here is the error I get when I try to access the web application.
GET http://localhost:8080//js/app.js net::ERR_CONNECTION_REFUSED
I think it should show IP address of my server instead of localhost. I don't know what's wrong with this but it's not working.
Laravel mix uses the webpack-dev-server package for the run hot command.
webpack-dev-server has a switch --useLocalIp which will make it use the servers local IP address.
It also has a --host switch which can be used to set the IP address manually --host 0.0.0.0

Run nodejs app through HTTPS

I have a node app that is setup on SSH by running node osjs run --hostname=dc-619670cb94e6.vtxfactory.org --port=4100.
It starts at http://dc-619670cb94e6.vtxfactory.org:4100/ without problems, but instead I want to serve it through HTTPS https://dc-619670cb94e6.vtxfactory.org:4100/ , where I receive an error ERR_CONNECTION_CLOSED.
If I use the port I'm unable to reach it with https, but https://dc-619670cb94e6.vtxfactory.org/ is accessible.
How can I serve the port 4100 through htttps?
Thanks.
This is an implementation detail of OS.js. Their docs recommend setting up a reverse proxy for servers. Doing this will give you more control over SSL and ports, like you want
https://manual.os-js.org/installation/

Accessing my node.js by others?

I have successfully launched my node.js server, and can access it through http://localhost:3000
How do I allow others see my development server? I do not have external IP.
For quick sharing in development stage there is a special NPM module called localtunnel. Do not use this method in production website due to security concerns.
Using localtunnel after you installed it (npm install -g localtunnel):
lt --port 3000
It shall output you the externally accessible URL after running the command, share this url with your friends.

403 Forbidden after successfully installing Ghost

I have been spending days figuring out how to install the viral Ghost platform, and experienced numerous errors. Luckily, I have managed to install it - Ghost gives me a positive Ghost is running... message in SSH after I've done npm start --production. However, when I browse to my website - http://nick-s.se - Apache displays its default page and when I go to the ghost login area - /ghost, the site returns a 403 Forbidden.
P.S. I have specifically installed Ghost on a different port than the one Apache is running on. I don't know what's going on...
Update - I have found out that I can access my Ghost installation by adding the port number 2368 which I've configured in the config.js. Now, however my problem is - how can I run Ghost without using such ports?...
tell your browser you want to connect to the port Ghost is running on: http://nick-s.se:2368
So a few things, based on visiting:
1) It seems Apache isn't proxying the request onward to Ghost. Are you sure that you've configured it properly?
2) It also looks like Apache doesn't have access to the directory that you set as root. This shouldn't be necessary anyway if proxying is set up correctly, but could become an issue later if you wanted to use apache to serve things like the static assets.
If you are open to nginx instead of Apache, I have written a how to on this: link. You can skip the section on configuring Nginx. Otherwise, still might be useful if you figure out the conversion of rules from Nginx to Apache.
If you don't have any other sites running on your VPS you can just turn apache off and not have to deal with apache proxying the request to port 2368 and have Ghost run on port 80. If your VPS is running CentOS you can check out this how to on disabling apache and running Ghost on port 80.

Resources