How to Install Nucleoid on Ubuntu 18.04
Tags: programming, database, javascript, node
Published: 2020-07-02 12:34:41

---
description: This article explains how to Install Nucleoid on Ubuntu 18.04 with configuration parameters and data storage.
---
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:

```bash
sudo apt-add-repository ppa:nucleoid/nucleoid
```

install as APT package:

```bash
sudo apt install nucleoid
```

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

{% link https://dev.to/nucleoid/hello-world-with-nucleoid-jo0 %}

## Terminal

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zfd4cokys6iljy7ag69r.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/w4b6aojvci7rundu01pc.png)

## 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`:

```json
{
  "process": "jwt-process.js"
}
```

`/opt/nucleoid/jwt-process.js`:

```javascript
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.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9y3ybfxzr4rhszzxx373.png)

## 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.

{% link https://dev.to/nucleoid/dbless-with-nucleoid-runtime-3o1k %}

Learn more at [nucleoid.org/tutorial](https://nucleoid.org/tutorial/)