Learn how to use the VTEX IO Node builder.
The node builder is used to develop backend apps with TypeScript code executed by the Node.js runtime. This guide aims to provide a comprehensive understanding of how to utilize this builder effectively. For further insights, refer to Developing services on VTEX IO.
Folder structure
An app that uses the node builder has a node folder on its root, where are located the following files and directories:
_12node_12 ┣ 📂 clients_12 ┗ 📄 {ClientCodeFileName}.ts_12 ┣ 📂 middlewares_12 ┗ 📄 {MiddlewareCodeFileName}.ts_12 ┣ 📂 event_12 ┗ 📄 {EventCodeFileName}.ts_12 ┣ 📄 {TypeScriptCodeFileName}.ts_12 ┣ 📄 index.ts_12 ┣ 📄 package.json_12 ┣ 📄 services.json_12 ┗ 📄 tsconfig.json
- TypeScript code files (
.tsextension) containing the core logic of the app, organized within various directories, such as:clients: Directory with the code files of Clients.middlewares: Directory with the code files of middlewares.event: Directory with the code files of event functions.
index.ts: Main TyepScript code file, where the execution begins. This file contains the main class of the service.package.json: JSON file describing the dependencies, script commands for building, and version details.services.json: Service configuration file used for defining the app parameters such as routes, events, time-to-live, etc. For more details, see Service configuration parameters.tsconfig.json: JSON file containing build configuration options.
Usage
To develop an app using the node builder, refer to the following steps:
- Start with a template: Download the
service-exampletemplate or create a new project using thevtex initCLI command and choose theservice-exampleoption. - Configure the
service.jsonfile: Edit theservice.jsonconfiguration file. For more information, see Service configuration parameters. - Configure permissions: If you want to access external resources, add the necessary policies to get permission for each resource in the
manifest.jsonand the corresponding Clients in the code to access the resources. - Implement the app's logic: Add the necessary TypeScript files containing the app logic.
- Testing: Link the app to a development workspace for testing.
Refer to Engineering guidelines for further information on scalability, performance optimization, data privacy best practices, and versioning.
Use case examples
Consider the following scenarios when using the node builder:
- Backend service development: If you are building backend services using Node.js, the
nodebuilder provides a streamlined development experience with native functions and clients for integrating with the VTEX ecosystem. - Event-driven applications: For applications that rely heavily on event-driven architecture, where actions trigger responses asynchronously, the
nodebuilder allows developers to implement event handlers and listeners. - Integration with external systems: When your application needs to integrate with external systems or APIs, such as payment gateways, databases, or third-party services, the
nodebuilder facilitates the development of client modules for interacting with these systems. - Custom middleware: If your application requires custom middleware for tasks like authentication, logging, or request processing, the
nodebuilder supports the creation and integration of middleware components.
Here are some app examples that use the node builder: