Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
NodeJs Application need guide in implementing php as template

Can anyone please guide me through to implement PHP as template for NodeJS application. I am planning to use : PHP to load only the front-end html template (security purpose) ExpressJs as my backend.

I got struck in implementing the same here i am attaching the code below :

var phpnode = require("php-node");
app.engine('php', phpnode);
app.set('view engine', 'php');

and I am trying to load template like this :

router.get('/index.php', function(req, res, next) {
    res.render('index.php');
});
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Minimal example:

File structure:

  1. ./test.js - our nodejs file
  2. ./php/ - our view folder with php files
  3. ./php/phpinfo.php - our test php file

./test.js:

var express = require('express'),
    app = express(),
    //make sure that `bin` location is right for you system
    phpnode = require('php-node')({bin:"/usr/local/bin/php"});

app.set('views', __dirname+'/php/');
app.engine('php', phpnode);
app.set('view engine', 'php');

app.all('/phpinfo.php', function(req, res) {
   res.render('phpinfo');
})

var port = process.env.PORT || 8081;
app.listen(port, function() {
  console.log("Listening on " + port);
})

./php/phpinfo.php

<?php phpinfo(); ?>

The open http://127.0.0.1:8081/phpinfo.php in your browser, you should see phpinfo text output (not a HTML, plain text, because php we ran in a CLI mode, exactly like if you ran it in terminal)

Tell me if you need it not in a CLI mode, I'll try to find out how to switch it..

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!