Neutered Puppy Masquerade
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    php-expresspublic

    php-express

    Add PHP support to your express server.

    Getting Started

    Express 4.x

    var express = require('express');
    var app = express();
     
    // must specify options hash even if no options provided!
    var phpExpress = require('php-express')({
     
      // assumes php is in your PATH
      binPath: 'php'
    });
     
    // set view engine to php-express
    app.set('views', './views');
    app.engine('php', phpExpress.engine);
    app.set('view engine', 'php');
     
    // routing all .php file to php-express
    app.all(/.+\.php$/, phpExpress.router);
     
    var server = app.listen(3000, function () {
      var host = server.address().address;
      var port = server.address().port;
      console.log('PHPExpress app listening at http://%s:%s', host, port);
    });
     

    Express 3.x

    var express = require('express'),
        http = require('http'),
        path = require('path'),
     
        // require php-express and config
        phpExpress = require('../')({
            binPath: '/usr/bin/php' // php bin path.
        });
     
     
    // init express
    var app = express();
    app.set('port', process.env.PORT || 3000);
    app.use(express.bodyParser());  // body parser is required!!
     
     
    // set view engine to php-express
    app.set('views', path.join(__dirname, 'views'));
    app.engine('php', phpExpress.engine);
    app.set('view engine', 'php');
    app.use(app.router);
    app.use(express.static(path.join(__dirname, 'public')));
     
     
    // routing all .php file to php-express
    app.all(/.+\.php$/, phpExpress.router);
     
     
    http.createServer(app).listen(app.get('port'), function(){
      console.log('Express server listening on port ' + app.get('port'));
    });

    Keywords

    install

    npm i php-express

    Downloadsweekly downloads

    45

    version

    0.0.3

    license

    BSD

    repository

    github.com

    last publish

    collaborators

    • avatar