Skip to content

setConfig

Configures global application settings such as security headers, logging, and static file serving.

Signature

js
app.setConfig(options)

Parameters

NameTypeDescription
optionsObjectConfiguration object with keys supported below.

Supported Options

OptionTypeDefaultDescription
portnumber3000Port to listen on when app.start() is called without arguments.
corsboolean | ObjectfalseEnables CORS. Pass true for defaults or an object for cors package options.
helmetboolean | ObjectfalseEnables Helmet security headers. Pass true or options.
logsbooleanfalseEnables HTTP request logging (via morgan).
bodyParserbooleantrueEnables/disables JSON and URL-encoded body parsing.
staticstring | booleanfalsePath to serve static files from (e.g., 'public').
viewsObjectundefinedConfigure view engine ({ engine: 'ejs', path: './views' }).

Examples

Basic Setup

js
app.setConfig({
  port: 8080,
  logs: true,
  static: 'public'
});

Security Extensions

js
app.setConfig({
  cors: { origin: 'https://example.com' }, // limits CORS to one domain
  helmet: true,                            // standard security headers
  bodyParser: false                        // disable if you want custom parsing
});

View Config

js
app.setConfig({
  views: {
    engine: 'ejs',   // or 'pug', 'hbs'
    path: './views'  // optional, defaults to ./views
  }
});

Toggling Features

Calling setConfig merges with existing config. You can disable features by setting them to false.

js
// previously enabled logs
app.setConfig({ logs: false }); // disables logging middleware

Released under the MIT License.