A template for creating custom services in nodeblock cloud service
This template provides the following features:
- Custom service template by using Nodeblocks backend SDK
- Built with TypeScript
- Run the service locally
- Example code with a simple todo feature
This project requires Node.js to be installed on your machine. Install the latest Node.js 18+ LTS version directly, or through nvm.
This project depends on npm packages hosted in a private npm registry.
You will need a npm auth token
in order to access these packages.
Please prepare this token using the steps below before continuing with setup.
- Ask Nodeblocks team for a valid
npm auth token
. - Add the token as
BASALDEV_AUTH_TOKEN
to your local environment -.zshrc
.bashrc
etc
export BASALDEV_AUTH_TOKEN=__INSERT_YOUR_TOKEN_HERE__
Create a .env
file in the root of the project by copying the .env.default
file. Update the values in the .env
file with the actual values.
cp .env.default .env
This file is used for npm run dev
command to run the service locally. You can configure the actual environment variables on NBC for production.
Run the following commands to install the required dependencies:
npm ci
The dependencies includes @basaldev/blocks-backend-sdk
which make easy to create the custom services.
Run the following command to start the application in development mode:
npm run dev
This command will start the application in development mode with hot reloading enabled. The application will automatically restart when you make changes to the code.
Run the following command to build the code:
npm run build
You need to build the code before to convert TypeScript code to runnable JavaScript. The transpiled code will be generated in the dist
folder.
Run the following command to start the application:
npm start
This template includes a simple todo feature to demonstrate how to create a custom service. Run the following command to start the example todo app:
npm run preview:todo
The todo feature includes the following endpoints:
GET /todos
- Get all todosPOST /todos
- Create a new todoGET /todos/:id
- Get a todo by idPUT /todos/:id
- Update a todo by idDELETE /todos/:id
- Delete a todo by id