Codeflow tutorial

Welcome to Codeflow tutorial. The below tutorials give a quick hands-on guide to Codeflow concepts before diving deep into the language guide.


    npm install -g codeflow        

Tutorial1 - Hello world

Let's build our first Codeflow project that prints a "hello world" to the console.

Step 1: Create a new project

This step assumes you have installed and opened the Codeflow designer.

Codeflow The above animation shows how to create a new project.

Open the designer and click 'Create project' button to create a new project. Give the name as hello-world and choose the location of your choice. Keep all other options as default. The Codeflow designer creates and opens up the new project. It will only contain a package.json.

Step 2: Creating a flow and printing "hello world"

In this step, we will create a new flow and print a hello world message to the console.

Codeflow The above animation shows how to create a flow and print "hello world".

  • In the project window, right click on the file panel and select the option New -> New flow.. from the context menu. Name it as hello. A flow by default will have two steps - A start and an end, the entry and exit point respectively.

  • For now, we will keep the start and the end untouched. To print a hello world message to the console, click open the console package in the packages panel and then drag the log module into the canvas.

  • The log module, when selected, will display a couple of tabs. The input tab is where you configure the properties of a module. For the log module, the only property is a string field named message. Every property accepts an expression as its value which is evaluated during the runtime. We will just use a hard-coded string message "hello world" (including double quotes) as the value of the message property. String fields should always be enclosed in double quotes. Apart from hard coded values, the expression fields can map output data from any of the previous steps and perform complex data transformations. We will cover it shortly.


  • A step is not invoked until it's connected to at least another step. Now, create two connections: One from the start to the log and second from the log to the end.

  • Now to start the flow, you can click the run button on the toolbar. The designer will open a terminal emulator and it should now display a "hello world" message.

Step 3: Pass your name and print it

In this step, we will configure the start step to accept an input value into the flow and later use it inside the log step.

Codeflow The above animation shows how to pass an input parameter and use it.

Let's pass a value into our new flow. To do that, you need to add a property in the start step.

  • Click on the start step and choose the schema tab. The schema tab is a special tab that is available for few special types of modules including the start and the end steps. The schema defined in the start step will become the input schema of the entire flow.

  • By default, the schema will be an empty object. Keep it like that and click the Add field button. Give the new field a name 'name' and keep the type as a string. The output of the start step will now be an object with a single property named 'name'. The output data of a step will be available for mapping in all the subsequent steps.

  • Now let's use that newly created field inside the flow. Navigate to the log step and select the input tab. Under the message, we will create a new expression to append the name and a "hello" message instead of just static "hello world".

  • Codeflow expressions can combine data with utility functions to do complex data transformations. Due to its functional design, every operation, including basic ones like a string concatenation or addition of two integers etc, are performed using functions. In order to append the name with a "hello" message, click on the expression and choose surround with function button from the drop down. This will switch the view to show all the available utility methods in the expression builder. You can search for concat method and select it.

  • Concat is a special method that takes a variable number of arguments. To concatenate the hard coded string message with the variable name that we want to pass, click on the plus arrow button and select start->output->name from the drop down under the data section.


Step 4: Running the flow in debug mode

We will use the debug mode to run the flow this time. The debugger executes the flow in the same way as the run button but will do so in the debug mode, which provides features such as highlighting the execution path and inspecting input and output data etc.

Codeflow The above animation shows how to debug a flow.

Step 5: Execute hello.flw from command line

In this step, we will execute the flow directly from the terminal/command line.

Codeflow The above animation shows executing a flow from the command line.

Install Codeflow engine, if you haven't done yet. Open a terminal or command prompt and navigate to the project folder and type:

cd <path to project's folder>
 codeflow run hello.flw

Will print:

 hello undefined

It is printing undefined because we haven't passed the input yet. Rerun the command by passing the input JSON -

codeflow run -i '{"name": "codeflow"}' hello.flw

This should print

hello codeflow


That's it. Congrats on completion of the hello world tutorial. What we have covered so far:

  • Understanding modules, packages, flows, steps, and transitions.
  • Start and End.
  • Configuring a step's input.
  • Basic understanding of input expressions.
  • Executing flows from the designer using the debugger.
  • Executing flows from a command line.

What's next?

Tutorial - A simple web server