This example assumes you are familiar with how serverless functions work. If needed, you can check Scaleway's official documentation
This example uses the Scaleway Serverless Framework Plugin. Please set up your environment with the requirements stated in the Scaleway Serverless Framework Plugin before trying out the example.
Finally, you will need Node.js installed in your computer to run this example.
By default, Node runtime treats files with the .js suffix. If you wish to use Typescript language with Node runtime, you can do so by following this example.
This example aims to show how to use Typescript language with Node runtime (node 18 runtime in this example). Used packages are specified in package.json.
The function in this example returns a simple "Hello world!" with a status code 200.
Once your environment is set up (see Requirements), you can install npm dependencies from package.json file using:
npm installThen, it is necessary to install the Typescript compiler package globally.
npm install -g typescriptYou can run tsc --version to ensure the compiler is correctly installed.
When this is done, you can initialize the Typescript project with Node.js. For that, you can run:
tsc --initThis will create a tsconfig.json file in the project root directory.
Before deploying your function, you need to transpile your Typescript code into brower readable JavaScript.
tscThe last step before deploying your function is to test it locally. For that, you can run:
NODE_ENV=test node handler.jsThis will launch a local server, allowing you to test the function. In another terminal, you can now run:
curl -X GET http://localhost:8080The expected output is "Hello world!".
Finally, if the test succeeded, you can deploy your function with:
serverless deployThen, from the given URL, you can check the result in a browser or by running the following command:
# Get request
curl -i -X GET <function URL>The output should be "Hello world!".