Kokos Template Node
Kokos Template Node is the template for creating a micro executor based on Node.js with typescript support. It encapsulate all standard features such as:
- types
- interfaces
- http support
- serverless support
- hot reload for development environment
- build
Getting Started
Kokos Template Node has an initialization script callable using NPX
.
npx @sme.up/kokos-template-node init [PROJECT_NAME]
The previous command create a folder called [PROJECT_NAME] and provides the first example.
Now you can install all dependencies:
npm install
and run in development mode (hot reload)
npm run dev:restapi
Create a Service
Kokos Node.js service is a Javascript Object based on KokosService
interface located under src/services
folder
services/[SERVICE_NAME].ts
import { KokosService } from "@sme.up/kokos-template-node";
const [SERVICE_NAME]: KokosService = {
methods: {
"HEL.WOR": helloWorld
}
}
function helloWorld(fun: Fun, context: ExecutionContext): SmeupTree {
const tree: SmeupTree = {
type: SmeupDataStructureType.SmeupTree,
children: [
{
children: [],
content: {
tipo: "",
parametro: "",
codice: "",
testo: "Hello World",
},
},
],
};
return tree;
}
The service exposes method called HEL.WOR
callable by FUN: F(TRE;[SERVICE_NAME];HEL.WOR)
Build
To properly build the micro executor you can run:
npm run build
Production
After the build you can test the micro executor in production mode launching:
npm run start:restapi
You can test your services by Swagger available at: http://localhost:3000/swagger/index.html