How do I put my scheduled website on Nodejs on the air?

Asked

Viewed 1,436 times

0

I am a PHP programmer and use the Filezilla for file management, this way, just putting the files inside a specific folder the hosting server looks for the file index and success.

In the case of Nodejs, start a server localhost, with the Listen in the main file, I am using the view engine EJS, that is, the pages are rendered according to the URL (server.get('/', (req, res) => {})) and not like conventional HTML files, follows an image with the root of my project:

inserir a descrição da imagem aqui

I would like to know how the server behaves with this structure, how and where to upgrade my project, and, if I need to change hosting. (I use the hosgator)

1 answer

3


There are many ways you can do this, so there’s no way I can put an answer by teaching step here.

Option 1

You can also use hostgator but it needs to be a VPS package. See Nodejs at the hostgator, you can open a ticket that they do the installation for you.

Option 2

You also have options that make deploying easier by simply using git as the Heroku and Netlify. These last two contain several tutorials on how to do it and it’s very simple, just configure the git part and modify some options in package.json that it does everything automatically.

Option 3

But being treated more manual. You can use the PM2 for persistence of your application, if you have an error or something like it does not break and the server falls.

The Nodejs by itself would already act as a server... In the same way that runs local, you would only have to leave this external ip.

Option 4

Other option is you put the rolling site Node on the server with the PM2 and use a . htaccess to redirect to that local address. How you handle PHP should be used to .htaccess. What you can do is create a rewrite on it, for example

RewriteEngine On
RewriteRule ^$ http://127.0.0.1:XXXXX/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:XXXXX/$1 [P,L]

Replace the XXXXX with your port that the Node server is running. That the redirect would work. Remember to use PM2 so that when an exception occurs or something breaks the application, the server does not fall.

  • Cool! But for example, I have apache installed on my server where I run some systems in PHP. And it runs on top of an address (example.net.br). How do I put my API running on: api.exemplo.net.br ?

  • You need to set up a DNS pointing to your server ip running in nodejs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.