alexandrevribeiro / express-app-runner

A ridiculously fast and easy way to configure and run an express app.
1 stars 1 forks source link

express-app-runner

Greenkeeper badge NPM version Travis Build Status AppVeyor Build Status

A ridiculously fast and easy way to configure and run an express app.

Installing

npm install express-app-runner --save

Documentation

Documentation is available here.

Samples

Running a simple app with an index.html as the homepage and making the content of the public directory available to the app:

var runner = require('express-app-runner');

// Defines an index page to be provided by '/'
runner.routeHomepageToFile('./index.html');

// Making the content of the 'public' directory available for the app though the '/' path.
// It may be useful to make JS and CSS files available to the app, 
// although most of the time you will probably be using a bundler like Webpack.
runner.addStaticDir('./public');

// Runs the app
runner.run();

A more complex sample:

var runner = require('express-app-runner');

// Defines an index page to be provided by '/'
runner.routeHomepageToFile('./index.html');

// Routes the "/users" to the "users.html"
runner.routeToFile('/users', './users.html');

// Routes the "/another" to the "another.html"
runner.routeToFile('/another', './../anyOtherDir/another.html');

// Making the content of the 'public' directory available for the app though the '/static' path
// It may be useful to make JS and CSS files available to the app, 
// although most of the time you will probably be using a bundler like Webpack.
runner.addStaticDir('./public', '/static');

// Routing any other endpoint
runner.app.get('/anything', function (req, res) {
    res.status(200).send('Anything!!!');
});

// Runs the app
runner.run({
    port: 4000,
    hostname: 'my_hostname',
    open: false,
    showListeningLog: false,
}, function(err) {
    doSomething();
});