Skip to main content

API

const app = nucleoid ( )

Creates application

const nucleoid = require("nucleoidjs");
const app = nucleoid();



app . get, post ( path , fn )

Creates routes

ArgumentDescriptionRequired
pathThe path that the application routes to.Yes
fnThe function that Nucleoid renders inside.

fn ( req )
req - contains http information:

req.body - JSON body
req.query - query params
req.params - path params
Yes
app.get("/orders", () => Orders.filter((order) => order.shipped));

app.post("/orders", () => new Order("SKU-123"));

app.get("/users/:id", (req) => User[req.params.id]);



app.listen ( port , callback )

ArgumentDescriptionRequired
portThe path that the application routes to.Yes
callbackThe function that Nucleoid renders.

Yes
app.listen(3000);



nucleoid.run ( fn , scope )

Runs function with scope

ArgumentDescriptionRequired
fnThe function that Nucleoid renders inside along with scope.Yes
scopeThe object of variables and values passed into Nucleoid runtime.No
const order = nucleoid.run(() => new Order());

const scope = { userId: 1 };
const user = nucleoid.run((scope) => new User(scope.userId), scope);



const express = app.express ( )

It gives an direct access to underlying Express.js libraries

const express = app.express();
express.get("/test", (req, res) => res.send("Hello"));