These examples won't run in the playground.

This is an advanced topic.

You can host a Clio project using clio host command, you'll be able to import the functions you hosted over the network, on server or in the browser. Let's define a function and host it:

fn on-ping ch:
fn on-ping-inner:
console.log "Ping received"
ch -> .send "pong"
export fn ping-pong:
channel () => ch
-> .on "ping" (on-ping ch)
title = "template-node"
description = ""
version = "0.1.0"
license = "MIT"
main = "src/main.clio"
authors = [ "Your Name <>" ]
keywords = ""
directory = "build"
target = "node"
directory = "src"
target = "node"
test = "No tests specified"
stdlib = "latest"
proto = "ws"
port = 1337
host = ""
name = "default"
proto = "ws"
url = "ws://localhost:1337"
count = "cpu"
server = "default"
proto = "ws"
url = "ws://localhost:1337"
wait_for = "cpu"
server = "default"

Running clio host in the root directory of the project will host the project. We can import this in another project:

import ping-pong from "ws://localhost:1337/main.clio"
fn on-pong:
console.log "Pong received"
export fn main:
await ping-pong () => ch
-> .on "pong" on-pong
fn ping:
ch -> .send "ping"
setInterval ping 1000

You can see full examples in our examples repository.