nyx init scaffolds a project: a nyx.toml
manifest and a src/main.nx entry point. We add one
line to declare the framework as a dependency.
$ nyx init notes-app $ cd notes-app
Open nyx.toml and add nyx-serve under [dependencies]:
# nyx.toml [package] name = "notes-app" version = "0.1.0" main = "src/main.nx" [dependencies] nyx-serve = "*"
"*" tells the package manager to fetch nyx-serve from
github.com/nyxlang-dev/nyx-serve into
packages/ on the next build. You can also pin a full
URL — nyx-serve = "https://github.com/nyxlang-dev/nyx-serve"
— or vendor the library into packages/ and commit it,
which is what production sites do for reproducible builds.
Replace src/main.nx with:
import "std/web" import "nyx-serve/src/server" fn home(req: Request) -> Response { return response_html(200, "<h1>notes-app</h1>") } fn main() { let app: App = app_new() app_get(app, "/", home) serve_app(app, 3000, 8) }
The three moving parts, from the imports:
std/web — the App, Request, Response core and the response_* constructors.nyx-serve/src/server — serve_app (the multi-threaded keep-alive server) and app_ws.src/files, src/template, src/multipart.$ nyx run notes-app starting on port 3000 with 8 workers
In another terminal:
$ curl http://localhost:3000/ <h1>notes-app</h1>
nyx run builds then runs. nyx build just
produces the binary (named after your package) — that single file is
what you copy to a server.