serve *.js
and *.jsx
files instantly over http.
- Install js-serve:
npm install js-serve
- Prepare your view directory:
mkdir ./views
- Add
*.js
or*.jsx
files, exporting afunction
(they now can return a Promise as well):
// ping.js
module.exports = function (ping) {
return ping + " - pong ";
};
curl http://localhost:8080/ping.js?ping=testping
returnstestping - pong
Order is of great importance, e.g. do not omit the port and the view folder if you want to specify the host.
js-serve <view-directory; default=./views> <port; default=8080> <host; default=localhost>
This module automatically imports all *.js
and *.jsx
files
from the specified folder. It then validates that the exported objects are functions.
Specified arguments (does only work when the functions are implemented
using the function
keyword) are then extracted - these will be required to be sent using query-parameters. Based on the folder-structure, the *.js
and *.jsx
files
can be invoked using a basic HTTP GET request.
- Support for functions that return Promises
- Dynamic Argument Sources: body, headers