I have shared hosting where I installed nodejs, so I am able to use node on apache hosting and can run HTML files easily with node.js files but I can't process PHP files.
After searching I found a link Can't Process PHP files with Node.js so I tried "php-express" library in order to run PHP files but unfortunately its downloading PHP file instead of running it:
var express = require('express')
var app = express()
var path = require('path');
var phpExpress = require('php-express')({
binPath: 'php'
});
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use('/', express.static(__dirname));
app.set('views', path.join(__dirname, '/views'));
app.engine('php', phpExpress.engine);
app.set('view engine', 'php');
app.all(/.+\.php$/, phpExpress.router);
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname , '/views/index.php'), function (err) {
if (err) {
res.status(500).send(err)
}
})
})
app.post('/registration', (req, res) => {
res.send(JSON.stringify(req.body));
});
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that")
});
app.listen(3000);
I want to get running WordPress site when I call example.com and when I call example.com/registration then I can able to use post method as shown in the code above.