How to Install Nucleoid on Ubuntu 18.04
Can Mingir
Posted on July 2, 2020
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
install as APT package:
sudo apt install nucleoid
This installs Nucleoid with its dependencies, and automatically starts at startup.
Hello World with Nucleoid
Can Mingir for Nucleoid ・ Jun 22 '20
Terminal
Once the installation is complete, Nucleoid starts its terminal, which is available at IP address of the server on a browser.
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.
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"
}
/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;
};
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.
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.
DBless with Nucleoid runtime
Can Mingir for Nucleoid ・ Jun 29 '20
Learn more at nucleoid.org/tutorial
Posted on July 2, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.