Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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');
});
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

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..

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda