I have a VPS in bluehost, I installed node and npm through SSH and I've managed to run a node app in www.mywebsite.com:3000, so I have two questions:
1) How do I run the app.js so when it 'listens' to www.mywebsite.com ? I mean when I go to www.mywebsite.com I see my index.ejs and everything like in my localhost instead of going to www.mywebsite.com:3000.
2) When I managed to run the node app in www.mywebsite.com:3000 it would close if I stopped the SSH conn, it doesn't stay 'forever', how do I start the server once and keep it up? Like with Heroku, where one would upload the package.json with the script "node app.js" and the server will always be up and running.
How I ran the node app in the port 3000:
First I ran npm init
, then I installed express npm install --save express
app.js:
var express = require("express");
var app = express();
app.get("/", function(req,res){
res.send("hi");
});
app.listen(3000, functions(){
console.log("Server Started");
});
i had the same issue but i resolved it
follow these steps:
1- open your ssh access from cpanel security then click manage ssh keys
2- click generate a new key then enter your password (you should remember your password as you will need it) then click generate key
3- after generating your new public key it will be listed in your public keys list click on manage then authorize your key
4- click on the private key for the public one you have just created (you will find private keys list under public keys)
5-insert your password then convert your key to ppk format then download it
6- download and install putty for ssh access
7- open putty then enter your host name and select ssh from the radio buttons list
8- after that on the left side under connection list open ssh list then click on auth
9- import your private key then click open
10- a new prompt will open enter your domain username (you'll find it in general information section in your cpanel) and your password which you used for converting your key to ppk format
11-if you could not connect to ssh, contact with bulehost support to enble your ssh access
12- after you are connected install nvm from this link https://github.com/nvm-sh/nvm
13- use the command nvm install for installing your required node version like nvm install 12.14.0
14- after that create your server folder then use npm for installing your required packages
15- first npm init then npm install****=>(your packages)
16- compress your server files then upload them to your server folder
17- go back to your putty ssh then navigate to your server folder
18- now write your command like node app.js it should work fine
19- for running nodejs as a backend service you can use forever (https://www.npmjs.com/package/forever )
Node 15 requires extra files or updates in bluehost. Node 10 works just fine. š
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With