From Node.js
To use the warped module from a Node.js script or another Node.js module, you need first to import the warped module. You also need to import the WarpJS Engine that will provide you access to the functions of the module you want to use in your script.
Import the warped module
In order to use it from HTML, the warped module should have been build in umd
format.
Then you can requires it with its path:
const MicroService = require('./warped_module.js')
Load WarpJS engine
WarpJS engine provides you the way to call functions of your warped module. You have to load it using a WarpJS engine module dependency.
Using a require
In case you cannot use or adapt your code to be asynchronous, you can directly import the engine, before requiring the warped module.
Of course you need to install it before using it
npm install @warpjs/engine
Then requires it
require('@warpjs/engine')
const MicroService = require('./warped_module.js')
Note that you have to manage yourself the dependency of the WarpJS engine that must be compatible with your warped module build.
Get warped module functions and use them
Now you have load the warped module and warp engine you can set your functions and call them.
const { hello } = new MicroService()
// Call the function on the warped module
hello('World').then((message) => {
console.log(message)
})
Full example
require('@warpjs/engine')
const MicroService = require('./warped_module.js')
const { hello } = new MicroService()
hello('World').then((message) => {
console.log(message)
})