Quick Start
In this quick tutorial, you'll learn how to create, emulate and deploy on a cloud your own Node.js module.
1. Create an empty module
First we will create a simple Node.js module in a my-module
directory:
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.
On our platform, a 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 our project 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 the SDK to access all CLI commands:
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. We provide a FREE community plan.
4. Build the module and run emulator on a development session
Use the warp dev
command to enter a development session with hot reload. At each changes of your Node.js module, it will update a my-module-client.js
file that will be used by a client script
to access your Node.js module either for during emulation or after deployment:
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>Accessing your Node.js module</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 our ScaleDynamics mutualized cloud will be used as cloud environment.
When the deployment process is done, open the generated URL in your browser. Your Node.js module is now running in the cloud.