Skip to content
NorscodeNorscode

Getting started

From an installed runtime to a web service that answers, in a few minutes.

Install the runtime

Get nc for your platform from downloads, and check that it answers:

nc --version

First program

Create a file hei.no:

funksjon start() -> heiltall {
    skriv("Hei, verden!")
    returner 0
}

Validate and run it:

nc check hei.no
nc run hei.no

nc check goes through syntax and types without running anything. nc run runs the program. A program always starts in the function start.

A web service

A route is an ordinary function that registers itself with web.route:

bruk std.web som web

funksjon forside(ctx: ordbok_tekst) -> ordbok_tekst {
    web.route("GET /")
    returner web.response_builder(200, {"content-type": "text/html; charset=utf-8"}, "<h1>It works</h1>")
}

funksjon start() -> heiltall {
    skriv("The service is ready")
    returner 0
}

Start it locally:

NORSCODE_VM_CAPABILITIES="net.tcp" \
NORSCODE_VM_NET_SCOPE="127.0.0.1" \
  nc serve tjeneste.no --host 127.0.0.1 --port 8080

Note the capabilities: without net.tcp the service does not bind a port. That is not a bug, it is the runtime doing its job.

Common early mistakes

  • missing capability means the program asked for something it was not granted. Add the capability to NORSCODE_VM_CAPABILITIES.
  • Unknown builtin function usually means a module was not imported. The entry file must import every module it uses, also indirectly.
  • Nothing happens? Remember that execution starts in start.

Next

Read What is Norscode for the language and the runtime model, or browse the standard library.