Why can't i run nodejs app from package.json in shared web hosting? - node.js

I can't run nodejs application from package.json in shared web hosting. It just runs the server.js or index.js file. So is there any way to run scripts from package.json?

First of all you can't change the entry point in shared web hosting. Second, you don't have control over shared hosted server to install node.js or even acces the actual directory in server. So no it's not possible do that without much control of the operating environment which I assume you are trying to deploy your app.
May I suggest an alternative to shared hosting, VPS hosting.
Virtual Private Server (VPS) is hosting that virtually mimics dedicated server environments within a shared server. VPS hosting is generally lower in cost than dedicated hosting but provides better reliability, security, and performance than shared hosting. Moreover, users get root access to the server, giving them the freedom to install applications and make environment changes without having to go through the hosting provider, as they would with shared hosting.

Related

Is it possible to create NodeJS apps on a shared hosting server?

My Bluehost hosting plan is such that I have my own domain, which is hosted on a shared server with other domains. After viewing some tutorials on deploying a NodeJS program through cPanel, I discovered that there was a "Setup NodeJS App" button only available to virtual private servers or dedicated servers. Is this really the only way? I know using ssh and the terminal I can run a NodeJS app, but can I fully deploy one and have it run on its own without my help or the command line? Is the only way to upgrade to virtual private server so that I have "enough control to deploy a NodeJS program" (words from Bluehost representative)?

Is it possible to deploy NodeJS app without SSH access?

According to that answer hosting that allows deploy NodeJS apps
will generally give you (at a minimum) shell access (via SSH) which
you can use to run the Node.JS application
But is it possible to deploy NodeJS application without access to ssh? On my hosting plan, I have only FTP access and I was wandering if I can do that or should I change hosting provider?
If your app is fully static you can build it into static js files (i.e. npm run build in vue.js) and then it should work on ftp hosting. Note, however, that in this case if your usage is low you can use something like Google App Engine or Netlify and essentially get free hosting for your static app.
However, if your app involves some back-end operations, i.e. express.js then you need to be able to run node.js server itself and you need a VPS-based or container-based hosting.
Feel free to reach out to me via discord here and ask more questions - https://discord.gg/UTxjBf9juQ.

how to run a node server in an azure virtual machine permanently?

I build a web based mobile app (using react), which I'm hosting as an Azure Web app. This website is connected to a node server, which I'm hosting using a azure virtual machine (I don't know if this is the best approach, maybe I should host this as a webapp instead of VM ?).
I'm still new to this strategie of developing a web based mobile app and connecting it to a hosted backend in the cloud so I apologize if this is a trivial question.
I'm using websockets to connect my frontend to the node server and then I consume messages. I don't have a database it is a simple application.
The steps I'm doing to run the app are:
I connect to the Azure VM from my laptop with ssh
run my server using node server.js
When the server is runing, I can refresh my website and everything works fine
Now, the problem is that I want the node server to run all the time. However, I noticed that the server stops running when I deconnect (ssh) my laptop from the virtual machine. So I find myself doing these steps (connecting to the VM with ssh and running the server manually) each time I want to use the app.
Is there a way to do this so that the node server runs all the time without stoping? Also since I'm new to this, is this the right way to deploy frontend and backend? I assume I can't deploy both frontend and backend in the same Azure webapp or am I wrong?
(Since part of your question is around "Is there a better way?", I would answer that instead of fixing the issue in your current VM hosting :)).
To take full advantage of cloud for your applications, PaaS is always preferred over IaaS. In this case, unless you have any specific reason, you should deploy your backend Node app in another App Service (aka Web App). Or you can consider Azure Function also if your node app has a small set of APIs, but it will require code update. Both support multiple platforms including node.js. Since you mentioned you are leveraging Web App for your react mobile app, so I hope you are already bit familiar with it. Also since Azure Function would require code change, so Web App is preferred this case.
Note: I omitted other solutions like AKS, Service Fabric etc. for now, since currently we are talking about the problem of deploying only a single app, for which those will be overkill at this moment.
Also, to your point
I assume I can't deploy both frontend and backend in the same Azure webapp or am I wrong?
Yes technically you can, depending on your scenario by "bundling" into a single app if both are in same platform (like Node in this case). Though whether one should do that would be an opinionated answer. But even if you keep those separate, you can still leverage single App Service Plan for cost saving. So keeping separate like you have now is what I would suggest to maintain "separation of concern".

ReactJS, Express application self hosting on internal dedicated IP server

I know we can host our ReactJS application on Amazon, Microsoft Azure, Heroku etc.
But what are the important steps and security precautions required to do in order to setup on an internal hosting server.
What are pros and corn of having Linux or Windows based server. (also which versions are relevant)
How to setup an SSL on local hosting server. What are options.
What are the security precautions to be made.
An internet line with dedicated IP from ISP can be connected, but do need to have any security hardware in middle in the network?
How to setup/connect a purchased domain name (www.mydomain.com) to an internal hosting server.
How to have multiple IPs to an internal hosting server, so if one server fails or one network fails the other keeps working with the purchased domain name.
How to log IP(visitors) access log in hardware level to keep server secure.
How to setup internal code version control system (using any local version control system and also GitHub), so if one deployment fails or creates any trouble; we can then restore to older code version.
How to setup a mailing server to send and receive emails and also how can we setup different emails on local hosting server.
Just had a look at the following link which contains most of the details related to most common server setup practice. Hopefully this will answer the question related to the server environment setup.
https://www.digitalocean.com/community/tutorials/5-common-server-setups-for-your-web-application
In the Related Articles Section (at end of the above article) there are lots of information on setting on NodeJS appliction on Ubunto etc. Hopefully the discussion there will clarify the concepts in more depth. e.g. How To Deploy a Node.js and MongoDB Application with Rancher on Ubuntu 16.04

Hosting with Nodejs?

I want to upload my first site in node. I have a hosting and domain bought. by default it comes with apache as web server.
Is there something I can configure using ftp to make it work with node, or should I communicate with the hosting provider to make it work with node?

Resources