Answer the question
In order to leave comments, you need to log in
How to run NodeJS script on beget?
New to nodeJS. I'm trying to run node js script on hosting beget. Gives the error that is on the screen. What am I doing wrong?
const express = require('express');
const bodyParser = require('body-parser');
const pdf = require('html-pdf');
const cors = require('cors');
const app = express();
const port = process.env.PORT || 5000;
app.use(cors());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.post('/create-pdf', (req, res) => {
pdf.create(require('./documents/letter'+req.body.tab_id)(req.body), {}).toFile('result.pdf', (err) => {
if(err) {
res.send(Promise.reject());
}
res.send(Promise.resolve());
});
});
app.get('/fetch-pdf', (req, res) => {
res.sendFile(`${__dirname}/result.pdf`)
})
app.listen(port, () => console.log(`Listening on port ${port}`));
Answer the question
In order to leave comments, you need to log in
Apparently you have Virtual Shared Hosting and Node is launched through the Passenger Apache module. This is a very limited mode and there is a lot of things that are not allowed. In particular, you cannot listen on ports like you do. Express uploads static files via Node stream and it doesn't work on such hosting either. You need to change your hosting plan to VPS/VDS.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question