First Steps
Starting
This guide will walk you through setting up your Blok development environment and creating your first nanoservice-based application. We aim to get you up and running as quickly as possible.
Prerequisites
Before you begin, ensure you have the following installed on your system:
- Node.js: Blok is built on Node.js. We recommend using the latest LTS version. You can download it from nodejs.org.
- npm (or yarn): npm is included with Node.js. If you prefer yarn, ensure it is installed.
Installation
The primary way to interact with Blok and manage your projects is through our Command Line Interface (CLI), blokctl.
You don't need to install blokctl globally to start. You can use npx to run the latest version directly:
Creating Your First Project
Let's create a new Blok project. Open your terminal and run:
npx blokctl@latest create projectThe CLI will guide you through the project creation process with an interactive interface:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+
|N|A|N|O|S|E|R|V|I|C|E|-|T|S| |C|L|I|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+
┌ Create a New Project
│
◇ Please provide a name for the project
│ nano-service
│
◇ Select the trigger to install
│ HTTP
│
◇ Select the runtimes to install
│ NodeJS
│
◇ Install the examples?
│ NO
│
◇ Project "nano-service" created successfully
Trigger: HTTP
Change to the project directory: cd nano-service
Run the command "npm run dev" to start the development server.
You can test the project in your browser at http://localhost:4000/health-check
For more documentation, visit https://blok.build/This will create a new directory with the name you provided, containing a fully configured Blok project.
Project Structure
After creating a new project, you'll have a directory structure like this:
NANO-SERVICE
├── node_modules/
├── notes/
│ ├── CLI_Commands/
│ ├── Core_Concepts/
│ ├── examples.md
│ └── index.md
├── public/
│ └── favicon.ico
├── src/
│ ├── nodes/
│ ├── types/
│ ├── workflows/
│ ├── HttpTrigger.ts
│ ├── index.ts
│ ├── MessageDecode.ts
│ ├── Nodes.ts
│ ├── opentelemetry_metrics.ts
│ ├── opentelemetry_traces.ts
│ ├── Util.ts
│ └── Workflows.ts
├── workflows/
│ ├── json/
│ ├── toml/
│ └── yaml/
├── .dockerignore
├── .env.example
├── .env.local
├── .gitignore
├── CHANGELOG.md
├── Dockerfile
├── nodemon.json
├── package-lock.json
├── package.json
├── request.http
├── supervisord.conf
└── tsconfig.jsonRunning Your First Application
The newly created project already includes a pre-configured example workflow called countries that fetches country data from an API. To run it:
-
Navigate to your project directory:
cd nano-service -
Start the development server:
npm run devNote that you don't need to run
npm installas this is already handled during project creation. -
Open your browser and navigate to:
http://localhost:4000/countriesOr use a tool like curl:
curl http://localhost:4000/countries
You should receive a JSON response with country data. The name of the workflow file corresponds to the endpoint URL, so countries is accessible at /countries.
Next Steps
Now that you have a basic understanding of how to set up and run a Blok project, you can explore further:
- Learn more about Nodes - the building blocks of your application.
- Understand Workflows in more detail.
- Discover how Triggers initiate your workflows.
- Dive into the Context Object for data sharing.
- Explore the available Examples for more complex use cases.
- Deepen your knowledge with the Fundamentals section.
Happy building!