Quick Start
In this quick tutorial, you'll learn how to create, emulate and deploy your own first warped module.
1. Create an empty module
First we will create a simple Node.js module in a my-module
directory, ready to be warped:
mkdir my-module
mkdir my-module/public
cd my-module/
npm init -y
index.js
module script
2. Create There should now be a package.json
file inside your module directory. We need to write our code to do something in this module.
A warped module must export asynchronous functions that will be transformed as microservice API calls.
In this example, we are simply writing an hello
function that returns some text, with the Node.js version.
Create a new index.js
file in the module directory, and copy-paste the following code into it:
// my-module/index.js
exports.hello = function (name) {
return `Hello ${name} from Node.js ${process.version}`;
};
3. Install WarpJS SDK and login
To install the SDK you need Node.js installed on your computer. Look to https://nodejs.org/en/download/ to install it.
Install WarpJS SDK that will provide all the commands to warp our module:
npm install warp --save-dev
Then login using your ScaleDynamics credentials:
npx warp login
Note that if you don't have a ScaleDynamics account yet, you can sign up here: https://console.scaledynamics.com/auth/signup/
4. Warp the module and run emulator
Use the warp dev
command to generate a my-module-client.js
file that will be used by a client script:
npx warp dev --output umd:./public/my-module-client.js
A cloud emulator server is now running on your computer.
5. Create a simple client script to call the warped module
First open a new terminal, and change to the public
directory:
cd public
Then create an index.html
file containing the following codes:
<!-- my-module/public/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Warped module client</title>
</head>
<body>
<script src="./my-module-client.js"></script>
<script>
const MyModule = window["my-module-client"];
MyModule.loadEngine().then(() => {
const { hello } = new MyModule();
hello("World").then((message) => {
document.body.innerHTML += message;
});
});
</script>
</body>
</html>
Next open that file on a local HTTP server with the following command:
cd ../
npx live-server public/
You will see it works! You can edit the my-module/index.js
file, and every change in the module will be hot reloaded in your web client.
We're now ready to deploy our module to the cloud.
6. Deploy the microservice in a cloud environment
Get back in the first terminal and stop the emulator (press CTRL+C
).
Next create a production build:
npx warp build --output umd:./public/my-module-client.js
And deploy the module in a cloud environment:
npx warp deploy
During the deployment, you'll be asked:
- to select a project. Select the project name you want.
- to select an environment. Create one with the name you want.
By default an Azure cloud platform will be used as cloud environment.
When the deployment process is done, open the generated URL in your browser. Your warped module is now running in the cloud.