API
const app = nucleoid ( )
Creates application
const nucleoid = require("nucleoidjs");
const app = nucleoid();
app . get, post ( path , fn )
Creates routes
Argument | Description | Required |
---|---|---|
path | The path that the application routes to. | Yes |
fn | The 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 )
Argument | Description | Required |
---|---|---|
port | The path that the application routes to. | Yes |
callback | The function that Nucleoid renders. | Yes |
app.listen(3000);
nucleoid.run ( fn , scope )
Runs function with scope
Argument | Description | Required |
---|---|---|
fn | The function that Nucleoid renders inside along with scope. | Yes |
scope | The 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"));