1 Context:
In this example, we will implement our own TypeScript backend function that looks up and returns the weather at a specific point on the globe; for this task, we will create a new endpoint in our TypeScript Node server (Nano)
2 Step by step guide:
- In your ProCode Workspace create a new folder
src/nano/src/service/training/ - Create a new file in that folder
src/nano/src/service/training/getweather.ts - Add an empty function to the file:
- Add the logic to fetch the data and return it to the function:
- The Nano server will automatically detect these changes and make them available without any additional actions; you can now call the service from the browser with the following call:
b1.v1.App.invokeServerTask({
name: "training/getweather",
methodType: "nano",
paramObj: { query: { lat: 52, lon: 10 } }
})Full Code Example:
3 Explanation:
The TypeScript backend functions allow you full access to a Node server, where you can implement any logic required. From simple tasks to complex calculations.