DEV Community

Cover image for How to Install Nucleoid on Ubuntu 18.04
Can Mingir for Nucleoid

Posted on

How to Install Nucleoid on Ubuntu 18.04

Nucleoid is an open source (Apache 2.0), a declarative runtime that enables declarative programming in ES6 (JavaScript) syntax and runs as a runtime and database at the same time.

On Linux, Nucleoid runs a service with accepting HTTP request, and dependent on a configuration, it creates process tree with sub-processes as multiprocessing.

Install

First, it requires to add official PPA repository into local APT package list:

sudo apt-add-repository ppa:nucleoid/nucleoid
Enter fullscreen mode Exit fullscreen mode

install as APT package:

sudo apt install nucleoid
Enter fullscreen mode Exit fullscreen mode

This installs Nucleoid with its dependencies, and automatically starts at startup.

Terminal

Once the installation is complete, Nucleoid starts its terminal, which is available at IP address of the server on a browser.

Alt Text

At the same time, it accepts POST request over the same IP with Content-Type: application/javascript. This entry is mostly used for interaction with API Gateways.

Alt Text

Configuration

/etc/nucleoid/configuration.json keeps configurations and it requires to restart after any changes.

/opt/nucleoid/ is for configuration scripts, which pointed in configuration.json.

Authorization: It takes Node.js script with optional imported modules and decides whether authorized the request, this is commonly used for integrating with Oauth server like Amazon Cognito, JWT, Active Directory etc.

Process: Nucleoid is a multiprocess runtime environment. So, each HTTP request has to be directed to dedicated process(es). This parameter takes Node.js script to decide or alternatively authorization server may provide this information, and the default process is main process.

Example:

/etc/nucleoid/configuration.json:

{
  "process": "jwt-process.js"
}
Enter fullscreen mode Exit fullscreen mode

/opt/nucleoid/jwt-process.js:

var jwt = require("jsonwebtoken");

module.exports = function(req, res) {
  let authorization = req.get("Authorization");
  let parts = authorization.split(" ");
  let payload = jwt.decode(parts[1]);
  return "users/" + payload.username;
};
Enter fullscreen mode Exit fullscreen mode

It looks at JWT token of username and redirects to process to users/[USERNAME].

Port: Port number of Nucleoid. Default is 80 with sudo privileges.

Processes

Nucleoid is a multiprocess environment with flexible deployment structure, which means processes can be created in-flight based on desired model. Once requested, Nucleoid spawns a brand new process with including storage reservation.

Processes are lazy initialized in Nucleoid, so that, after reboot or manually killed, processes won’t start unless needed.

Alt Text

Data Location

Nucleoid runs a programming runtime and database, so each statement is stored at /var/lib/nucleoid/ folder, and each process has own storage space with Single-lined JSON format.

Single-lined JSON

Nucleoid stores declarative statements as appending data file, which provides ubiquitous human-readable files and faster disk operation.

Learn more at nucleoid.org/tutorial

Top comments (0)