3

I'm very new to node.js and don't have much knowledge about servers. I made a node app and started it in my server (who has some other websites in php, so it needs to work with apache) using node server.js &. It was working great, and it kept running until the next day, when I got the 503 error. Got into my server again using ssh and noticed it wasn't working, so I started again with nodemon running nodemon server.js &.

Same thing, several hours later I got 503 error again.

The steps I followed:
1. created the website folder inside /var/www/
2. created the website configuration inside /etc/apache2/sites-available/ (mysite.com.conf file showed bellow)
3. enabled the site using e2ensite
5. ran cerbot for SLL certificate
6. reloaded apache
7. started the app with nodemon server.js > log.out &

I created the mysite.com.conf as seen bellow:

    <VirtualHost *:80>
        ServerAdmin user@MAINDOMAIN.com
        ServerName MYSITE.MAINDOMAIN.com
        ServerAlias www.MYSITE.MAINDOMAIN.com
        DocumentRoot /var/www/MYSITE.MAINDOMAIN.com/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory "/var/www/MYSITE.MAINDOMAIN.com/public">
            Options FollowSymLinks
            AllowOverride All

            Order allow,deny
            Allow from all
        </Directory>
        ProxyPass / http://127.0.0.1:7000/
        ProxyPassReverse / http://127.0.0.1:7000/
        RewriteEngine on
        RewriteCond %{SERVER_NAME} =MYSITE.MAINDOMAIN.COM [OR]
        RewriteCond %{SERVER_NAME} =www.MYSITE.MAINDOMAIN.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} 
        [END,NE,R=permanent]
    </VirtualHost>

And my server.js file looks like this:

    const express = require('express')
    const mysql = require('mysql')
    const app = express()

    //mysql database connection here

    //some app.get() here to render pages

    const server = app.listen(7000, () => {
        console.log('Express running on port ${server.address().port}');
    });

The last message I got in the log.out it's app crashed - waiting for file changes before starting.

How can I keep this running? Did I do something wrong?

msanford
  • 11,803
  • 11
  • 66
  • 93
Flávia Nunes
  • 251
  • 1
  • 3
  • 14

1 Answers1

0

Started using forever with --exitcrash.

Flávia Nunes
  • 251
  • 1
  • 3
  • 14