L
L
LionG2019-03-04 15:36:34
Node.js
LionG, 2019-03-04 15:36:34

How to do error handling for EJS so that the server does not crash?

If something went wrong in the ejs file, then the server crashes.
Program node server.js exited with code 1
How to process it so that, for example, if an error occurs, then render another file and not kill the server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Laud, 2019-03-06
@LionG

try {
    // что-то делаете
} catch (error) {
    // обрабатываете ошибку
}

But error handling can't always guarantee that the program will never crash, so it's worth using process managers like forever . They will restart the process on crashes.
Installation:
Starting the server (instead of node server.js)
forever start server.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question