How can I use my host, a regular dream host acct as a node server? - node.js

I've tried some methods online using ssh but can't figure it out. why is it so difficult to install when it's basically just Javascript?

A regular Dreamhost account will not allow a long running process which a node server is. You will need a VPS account.
Also, the node application and V8 engine inside it is not just javascript. It's an actual native application. Your scripts are "just javascript", but the infrastructure that makes the node server run is native code.

In 2015, Dreamhost started to support the deployment of nodejs (as well as ruby, python) applications through the Passenger domain option. For more information on Passenger, check Node.js with Passenger tutorial.
Unfortunately, this is available only on VPS running Unbuntu.
Note that on the Dreamhost wiki, under Nodejs, they write
DreamHost does not support node.js on shared web servers, as the security setup on DreamHost shared servers is incompatible with compiling or running node.js. If you try to compile node.js on one of the shared web servers, your user will automatically be banned through grsec (taking down all the php websites that run under that user) and the server will have to be rebooted before your user can be unbanned. If you do it one more time, you will be forced to move to a VPS.

Related

Deploying Next.js to Apache server

I've been developing a Next.js website locally and now want to set it up on my Apache server (with cPanel). However, I'm very new to Next.js and Node apps and not too sure how to go about it.
Has anyone done this successfully? Can you list the required steps and what files should be on the server?
Also, can this be done on a subdomain?
Thank you!
To start with some clear terms just so we're on the same page, there are two or three very different things people mean when they say "server":
A Server Machine is a computer that is connected to the internet that you intend to use to serve something to people on the internet.
A Server Program is some software you run on your Server Machine. The job of the Server Program is to actually calculate the responses to various requests.
A Server as a Service is a webapp provided by a company that stores your code and then puts it onto Server Machines with the right Server Program as needed.
While we're here, let's also define:
A Programming Language is the language your website is written in. Some sites have no language (and are just raw HTML/CSS files that are meant to be returned directly to the user). Many sites, though, have some code that should be run on the server and then the result of that code should be returned to the user.
In your case, you have a Machine whose condition we don't know other than that it is running the Program Apache (or probably "Apache HTTP Server"). Apache HTTP server is very old and proven and pretty good at serving raw files back to users. It can also run some Programming Languages like PHP and return the result.
However, Next.JS is built on top of the Programming Language Javascript, which Apache does not have the ability to run. Next.JS instead wants its Server Program to be Node.
So the problem here is basically that you have a hammer, but only screws. You can't use the tool you have, Apache, to solve the problem you need solved, running Node code and returning the result. To get around this you have two options:
First, you can find a way to access the Server Machine that is currently running Apache and tell it, instead, to run Node pointed at your Next.JS code whenever it starts up. This might not be possible, depending on who owns this machine and how they've set it up.
Second, and probably easier, is to abandon this Machine and instead use a Server as a Service. Heroku, AWS, and Netlify all support Next.JS and have a free tier. The easiest solution, though, is probably to just deploy it on Vercel, which is a Server as a Service run by the same team that makes Next.JS and which has a very generous free tier for you to get started with.
The good news, though, is that yes next.js does totally support being hosted from a subdomain.
Next.JS allows you to build fully functional Node Applications, as well as simple statically-generated sites like Jeckyl or Docpad. If your use case is a simple statically generated site look here: https://nextjs.org/docs/advanced-features/static-html-export
In particular the next build && next export command will create all the HTML and assets necessary to host a site directly via an HTTP server like Apache or Ngnix. Contents will be outputed to an out directory that could serve as the server root.
Pay very close attention to what features are not supported via this approach.

Deploy ReactPHP on PHP host

I use the example for the chat server in ReactPHP. My server listens on port 8080
$socket = new React\Socket\Server(8080, $loop);
$server->listen($socket);
in my local PC. The written code is working correctly but when upload files into my Linux host, nothing works. I wrote a ticket to the support team from my hoster, they said that this is not possible in Linux. Is that correct?
ReactPHP core team member here. Your run-of-the-mill shared hosting won't be able to host this. You need your own server, VPS, or bare metal, to run ReactPHP as a server because you're dealing with a daemon process. And shared hosting generally doesn't support that.
My suggestion is to get a VPS somewhere and look into Supervisor to keep your process running and restart it when something happens to it. This also requires you to manage your own server with all the firewalling and networking knowledge that comes with it.

Namecheap Shared Hosting & Multiple Node JS Apps

Is it possible to have multiple Node JS apps run on a single shared hosting plan running cPanel?
I have successfully installed the specific version of Node JS to my cPanel account using the following reference:
http://vinyll.scopyleft.fr/installing-a-custom-version-of-node-on-a-shared-hosting/
Now I just need to take my existing Node JS apps and get them running. I found the following helpful article on this so far:
https://www.ionicrun.com/running-a-node-js-application-on-shared-hosting/
I believe I can make sense of the instructions from the above link. However, the problem becomes how can I run multiple Node JS apps in one cPanel account?
Run your app in different port. Check for free ports and user any of them.
I usually use ports from 3000 to 4000. But, make sure your port is free.

How to build a Node.js application with web hosting service?

Is it possible to build a node application with a web hosting service, such as blue host, godaddy or media temple? Or does it need to be on a hosting site such as Heroku or Back4App? If so where do I start to learn how to do this?
"Web hosting" is a pretty broad term, but typically you're going to see static HTML, and some hosted PHP, and a few other technologies. It's atypical to see Node.js application hosting as part of a general web hosting package. The reason is that you're going to want more control over the environment in which it runs.
That gives you a couple general classes of options:
Virtual or Dedicated Hosting
Having a VPS instance, or even a full machine if you can afford it, gives you full access to the OS and what you install on it. This means you can run whatever you want, including Node.js. You can get very cheap VPS hosting.
Node.js Application Hosting
This is the sort of service you get with Heroku or on AWS Elastic Beanstalk. Your application more directly integrates with the hosting provider, allowing you to take advantage of some of their automation and deployment tooling. If you need to do any automatic scaling, this is your best option.
You can try one of this five:
RedHat OpenShift
Nodejitsu
Microsoft Azure (don't!, well... try if you want to)
Modulus
Heroku (my fauvorite)
You can see details of each one here! But I would start with heroku app, but it's your choice
To get started with heroku
Godaddy does allow nodejs as part of its "web hosting" offering:
https://www.godaddy.com/pro/one-click-installation/node-js
That said, I really recommend Heroku and similar services for having less upsell and letting you work closer to cruft-free.

Deploy a MEAN stack application to an existing server

I have a Ubuntu Server on DigitalOcean which hosts a website, and a Windows Server on AWS which hosts another website.
I just built a mean.js stack app on my MAC, and I plan to deploy it to production.
It seems that most of the existing threads discuss about using a new dedicated server. For example, this thread is about deploying on a new AWS EC2 instance; this video is about deploying on a new Windows Azure server; this is to create a new droplet in DigitalOcean.
My question is, is it possible to use an existing server (which hosts other websites), rather than creating a new server? If yes, will there be any difference in terms of performance?
My question is, is it possible to use an existing server (which hosts other websites), rather than creating a new server?
Yes. Both Windows and Ubuntu allows you to deploy multiple applications on same instance.
For Ubuntu you can read this post which will help you server multiple apps.
In this example used Nginx, but you can follow to this example and use it without any server like Apache or Nginx. If you need subdomains I would suggest to use Apache virtual hosts with reverse proxy module and pm2
For Windows and its IIS I would suggest to use iisnode, in google you can find a lot of articles how to configure it.
will there be any difference in terms of performance?
It is depended on your applications, if you are already serving applications which handles huge traffic and need CPU and memory, I would not suggest you to use multiple apps on same instance, but if you are going to use simple web apps, you can easily use same instance.
Hope this answer will help you!

Resources