Class: JovaServer
Defined in: src/JovaServer.ts:43
Extends
EventEmitter
Constructors
Constructor
new JovaServer(
options
:JovaServerOptions
):JovaServer
Defined in: src/JovaServer.ts:59
Parameters
Parameter | Type |
---|---|
options | JovaServerOptions |
Returns
JovaServer
Overrides
EventEmitter.constructor
Properties
all
readonly
all:IRouterMatcher
<Express
> =container.express.all
Defined in: src/JovaServer.ts:185
Name
App.all
Description
Special-cased "all" method, applying the given route path
, middleware, and callback to every HTTP method.
This method is like the standard methods, except it matches all HTTP verbs.
See
Express Docs: Application.all()
Param
string
Param
any
any
readonly
any:IRouterMatcher
<Express
> =container.express.all
Defined in: src/JovaServer.ts:171
Name
App.any
Description
Alias for all
.
This method is like the standard methods, except it matches all HTTP verbs.
See
Express Docs: Application.all()
Param
string
Param
any
delete
readonly
delete:IRouterMatcher
<Express
> =container.express.delete
Defined in: src/JovaServer.ts:228
Name
App.delete
Description
Contextual function.
HTTP DELETE:
Routes HTTP DELETE requests to the specified path with the specified callback functions.
See
Express Docs: Application.delete()
Param
string
Param
any
engine()
readonly
engine: (ext
:string
,fn
:Function
) =>Application
=container.express.engine
Defined in: src/JovaServer.ts:384
Register the given template engine callback fn
as ext
.
By default will require()
the engine based on the
file extension. For example if you try to render
a "foo.jade" file Express will invoke the following internally:
app.engine('jade', require('jade').__express);
For engines that do not provide .__express
out of the box,
or if you wish to "map" a different extension to the template engine
you may use this method. For example mapping the EJS template engine to
".html" files:
app.engine('html', require('ejs').renderFile);
In this case EJS provides a .renderFile()
method with
the same signature that Express expects: (path, options, callback)
,
though note that it aliases this method as ejs.__express
internally
so if you're using ".ejs" extensions you dont need to do anything.
Some template engines do not follow this convention, the Consolidate.js library was created to map all of node's popular template engines to follow this convention, thus allowing them to work seamlessly within Express.
Parameters
Parameter | Type |
---|---|
ext | string |
fn | Function |
Returns
Application
Name
App.engine
Description
Registers the given template engine callback
as ext
.
See
Express Docs: Application.engine()
Param
string
Param
(path: string, options: object, callback: (e: any, rendered?: string) => void) => void
get
readonly
get: (name
:string
) =>any
&IRouterMatcher
<Express
> =container.express.get
Defined in: src/JovaServer.ts:211
Name
App.get
Description
Contextual function.
HTTP GET:
Routes HTTP GET requests to the specified path with the specified callback functions.
See
Description
Get Setting:
Returns the value of name app setting, where name is one of the strings in the app settings table.
Param
get) path string
Param
get) callback any
Param
setting) setting string | JovaSettingsOptions
head
readonly
head:IRouterMatcher
<Express
> =container.express.head
Defined in: src/JovaServer.ts:306
Name
App.head
Description
Routes HTTP HEAD requests to the specified path with the specified callback functions.
See
Express Docs: Application.head()
[ NO DOCUMENTATION CURRENT ]
Param
string
Param
any
locals
locals:
any
=container.express.locals
Defined in: src/JovaServer.ts:404
Name
App.locals
Description
The locals
object has properties that are local variables within the application,
and will be available in templates rendered with response.render.
Once set, the value of locals
properties persist throughout the life of the application,
in contrast with response.locals properties that are valid only for the lifetime of the request.
You can access local variables in templates rendered within the application.
This is useful for providing helper functions to templates, as well as application-level data.
Local variables are available in middleware via request.app.locals
.
See
Express Docs: Application.locals
locals is also a property of the container
object.
middleware
readonly
middleware:IRouterHandler
<Express
> &IRouterMatcher
<Express
> =container.express.use
Defined in: src/JovaServer.ts:350
Name
App.middleware
Description
Mounts the specified middleware function or functions at the specified path:
the middleware function is executed when the base of the requested path matches path
.
See
Express Docs: Application.use()
Param
string
Param
any
options
readonly
options:IRouterMatcher
<Express
> =container.express.options
Defined in: src/JovaServer.ts:320
Name
App.options
Description
Routes HTTP OPTIONS requests to the specified path with the specified callback functions.
See
Express Docs: Application.options()
Param
string
Param
any
param()
readonly
param: {(name
:string
|string
[],handler
:RequestParamHandler
):this
; (callback
: (name
:string
,matcher
:RegExp
) =>RequestParamHandler
):this
; } =container.express.param
Defined in: src/JovaServer.ts:239
Call Signature
(
name
:string
|string
[],handler
:RequestParamHandler
):this
Map the given param placeholder name
(s) to the given callback(s).
Parameter mapping is used to provide pre-conditions to routes which use normalized placeholders. For example a :user_id parameter could automatically load a user's information from the database without any additional code,
The callback uses the samesignature as middleware, the only differencing
being that the value of the placeholder is passed, in this case the id
of the user. Once the next()
function is invoked, just like middleware
it will continue on to execute the route, or subsequent parameter functions.
app.param('user_id', function(req, res, next, id){
User.find(id, function(err, user){
if (err) {
next(err);
} else if (user) {
req.user = user;
next();
} else {
next(new Error('failed to load user'));
}
});
});
Parameters
Parameter | Type | Description |
---|---|---|
name | string | string [] | |
handler | RequestParamHandler | - |
Returns
this
Call Signature
(
callback
: (name
:string
,matcher
:RegExp
) =>RequestParamHandler
):this
Map the given param placeholder name
(s) to the given callback(s).
Parameter mapping is used to provide pre-conditions to routes which use normalized placeholders. For example a :user_id parameter could automatically load a user's information from the database without any additional code,
The callback uses the samesignature as middleware, the only differencing
being that the value of the placeholder is passed, in this case the id
of the user. Once the next()
function is invoked, just like middleware
it will continue on to execute the route, or subsequent parameter functions.
app.param('user_id', function(req, res, next, id){
User.find(id, function(err, user){
if (err) {
next(err);
} else if (user) {
req.user = user;
next();
} else {
next(new Error('failed to load user'));
}
});
});
Parameters
Parameter | Type |
---|---|
callback | (name : string , matcher : RegExp ) => RequestParamHandler |
Returns
this
Name
App.param
Description
Add callback triggers to route parameters.
See
Express Docs: Application.param()
path()
readonly
path: () =>string
=container.express.path
Defined in: src/JovaServer.ts:419
Return the app's absolute pathname based on the parent(s) that have mounted it.
For example if the application was mounted as "/admin", which itself was mounted as "/blog" then the return value would be "/blog/admin".
Returns
string
Name
App.path
Description
Returns the canonical path of the application, a string.
The behavior of this method can become very complicated in complex cases of mounted apps: it is usually better to use request.baseUrl to get the canonical path of the application.
See
Express Docs: Application.path()
post
readonly
post:IRouterMatcher
<Express
> =container.express.post
Defined in: src/JovaServer.ts:252
Name
App.post
Description
Routes HTTP POST requests to the specified path with the specified callback functions.
See
Express Docs: Application.post()
Param
string
Param
any
put
readonly
put:IRouterMatcher
<Express
> =container.express.put
Defined in: src/JovaServer.ts:265
Name
App.put
Description
Routes HTTP PUT requests to the specified path with the specified callback functions.
See
Express Docs: Application.put()
Param
string
Param
any
render()
readonly
render: {(name
:string
,options
?:Object
,callback
?: (err
:Error
,html
:string
) =>void
):void
; (name
:string
,callback
: (err
:Error
,html
:string
) =>void
):void
; } =container.express.render
Defined in: src/JovaServer.ts:278
Call Signature
(
name
:string
,options
?:Object
,callback
?: (err
:Error
,html
:string
) =>void
):void
Render the given view name
name with options
and a callback accepting an error and the
rendered template string.
Example:
app.render('email', { name: 'Tobi' }, function(err, html){ // ... })
Parameters
Parameter | Type | Description |
---|---|---|
name | string | |
options ? | Object | or fn |
callback ? | (err : Error , html : string ) => void | - |
Returns
void
Call Signature
(
name
:string
,callback
: (err
:Error
,html
:string
) =>void
):void
Parameters
Parameter | Type |
---|---|
name | string |
callback | (err : Error , html : string ) => void |
Returns
void
Name
App.render
Description
Returns the rendered HTML of a view via the callback
function.
It accepts an optional parameter that is an object containing local variables for the view.
It is like response.render(), except it cannot send the rendered view to the client on its own.
See
Express Docs: Application.render()
route()
readonly
route: (prefix
:PathParams
) =>IRoute
=container.express.route
Defined in: src/JovaServer.ts:290
Parameters
Parameter | Type |
---|---|
prefix | PathParams |
Returns
IRoute
Name
App.route
Description
Returns an instance of a single route, which you can then use to handle HTTP verbs with optional middleware.
Use route
to avoid duplicate route names (and thus typo errors).
See
Express Docs: Application.route()
use
readonly
use:IRouterHandler
<Express
> &IRouterMatcher
<Express
> =container.express.use
Defined in: src/JovaServer.ts:335
Name
App.use
Description
Mounts the specified middleware function or functions at the specified path:
the middleware function is executed when the base of the requested path matches path
.
See
Express Docs: Application.use()
Param
string
Param
any
Methods
listen()
readonly
listen(port
:undefined
|string
|number
,allowPortIncrement
?:boolean
):Promise
<void
>
Defined in: src/JovaServer.ts:442
Parameters
Parameter | Type | Description |
---|---|---|
port | undefined | string | number | |
allowPortIncrement ? | boolean |
Returns
Promise
<void
>
Name
App.listen
Description
Start the Jova Server, begin listening to a port & its incoming requests.
Examples
const server = new JovaServer();
await server.listen(3000); // Without port increment
const server = new JovaServer({ port: 3000 });
await server.listen();
const server = new JovaServer();
await server.listen(3000, true); // With port increment
set()
readonly
set(Name
:string
,Value
:any
):Application
Defined in: src/JovaServer.ts:369
Parameters
Parameter | Type | Description |
---|---|---|
Name | string | JovaSettingsOptions |
Value | any | any |
Returns
Application
Name
App.set
Description
Assigns setting name to value. You may store any value that you want, but certain names can be used to configure the behavior of the server. These special names are listed in the app settings table.
Calling application.set('foo', true) for a Boolean property is the same as calling application.enable('foo'). Similarly, calling application.set('foo', false) for a Boolean property is the same as calling application.disable('foo').