最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Deploy nodejs app to bluehost - Stack Overflow

programmeradmin2浏览0评论

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:3000, so I have two questions:

1) How do I run the app.js so when it 'listens' to www.mywebsite ? I mean when I go to www.mywebsite I see my index.ejs and everything like in my localhost instead of going to www.mywebsite:3000.

2) When I managed to run the node app in www.mywebsite: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 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");
});
Share Improve this question edited Aug 9, 2017 at 9:45 Vadim Kotov 8,2848 gold badges50 silver badges63 bronze badges asked Jan 11, 2017 at 17:55 LuisEganLuisEgan 1,0242 gold badges14 silver badges29 bronze badges 5
  • 1 Re: #1 you should create a reverse proxy from port 80 or 443 using another server like apache or nginx to port 3000 (or whatever port you specify to run the nodejs app on). #2: speaking of forever -- pm2 is also a good alternative – Explosion Pills Commented Jan 11, 2017 at 18:03
  • I actually used the port 3000 to the test, is it necessary to use a reverse proxy to deploy a nodejs app, or just if I want it in a specific port? – LuisEgan Commented Jan 11, 2017 at 19:02
  • I used forever and now app.js stays up. I also changed the app.js to listen to port 80 but it doesn't work. There is already an index.html in the public_html directory and it is loading that, how do I get it to load app.js first? – LuisEgan Commented Jan 11, 2017 at 19:32
  • You should use a reverse proxy for port 80/443 (SSL Termination). If port 3000 is open to the world based on your firewall / network settings you can still access it directly as well. If you want to run a test vs. production version of the app I would do that on separate servers. – Explosion Pills Commented Jan 11, 2017 at 19:32
  • ok, I understand what your are saying but I don't know how to do it.. though it doesn't answer if that is necessary or good practice. How do I use a reverse proxy in centos 6? – LuisEgan Commented Jan 11, 2017 at 22:33
Add a comment  | 

3 Answers 3

Reset to default 10

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.

发布评论

评论列表(0)

  1. 暂无评论