2021-02-25 16:01:36 +01:00
---
title: Getting Started
---
2021-05-18 11:19:33 +02:00
> This section only applies if you plan to self-host Unleash. If you are looking for our hosted solution you should head over to [www.getunleash.io](https://www.getunleash.io/plans)
2021-02-25 21:00:19 +01:00
2021-06-04 11:17:15 +02:00
## Requirements {#requirements}
2021-02-25 16:01:36 +01:00
You will need:
2023-05-05 09:17:34 +02:00
- [Node.js ](https://nodejs.org/en/download/ ) (version 18 or later)
2021-02-25 16:01:36 +01:00
- [PostgreSQL ](https://www.postgresql.org/download/ ) (version 10 or later)
2021-05-21 21:30:29 +02:00
- [Create an unleash user and database ](./database-setup ).
2021-02-25 16:01:36 +01:00
2021-06-04 11:17:15 +02:00
## Start Unleash server {#start-unleash-server}
2021-02-25 16:01:36 +01:00
2021-05-18 11:19:33 +02:00
Whichever option you choose to start Unleash, you must specify a database URI (it can be set in the environment variable DATABASE_URL). If your database server is not set up to support SSL you'll also need to set the environment variable `DATABASE_SSL` to `false`
---
2021-02-25 16:01:36 +01:00
Once the server has started, you will see the message:
```sh
Unleash started on http://localhost:4242
```
2021-05-21 21:30:29 +02:00
2021-05-18 14:21:39 +02:00
To run multiple replicas of Unleash simply point all instances to the same database.
2021-05-18 11:19:33 +02:00
**Unleash v4:** The first time Unleash starts it will create a default user which you can use to sign-in to you Unleash instance and add more users with:
- username: `admin`
- password: `unleash4all`
2021-09-23 21:18:44 +02:00
### Option 1 - use Docker {#option-one---use-docker}
2021-03-17 07:34:23 +01:00
**Useful links:**
- [Docker image on dockerhub ](https://hub.docker.com/r/unleashorg/unleash-server/ )
- [Unleash Helm Chart on artifacthub ](https://artifacthub.io/packages/helm/unleash/unleash )
**Steps:**
1. Create a network by running `docker network create unleash`
2. Start a postgres database:
2021-02-25 16:01:36 +01:00
```sh
2021-03-17 07:34:23 +01:00
docker run -e POSTGRES_PASSWORD=some_password \
-e POSTGRES_USER=unleash_user -e POSTGRES_DB=unleash \
--network unleash --name postgres postgres
2021-02-25 16:01:36 +01:00
```
2021-03-17 07:34:23 +01:00
3. Start Unleash via docker:
```sh
docker run -p 4242:4242 \
-e DATABASE_HOST=postgres -e DATABASE_NAME=unleash \
-e DATABASE_USERNAME=unleash_user -e DATABASE_PASSWORD=some_password \
2021-05-18 11:19:33 +02:00
-e DATABASE_SSL=false \
2021-11-23 09:43:35 +01:00
--network unleash --pull=always unleashorg/unleash-server
2021-03-17 07:34:23 +01:00
```
2021-09-23 21:18:44 +02:00
### Option 2 - use Docker-compose {#option-two---use-docker-compose}
2021-11-23 09:43:35 +01:00
2021-09-23 21:18:44 +02:00
**Steps:**
2021-11-23 09:43:35 +01:00
2023-03-31 12:42:34 +02:00
1. Clone the [Unleash repository ](https://github.com/Unleash/unleash ).
2023-02-03 10:39:14 +01:00
2. Run `docker compose up -d` in repository root folder.
2021-03-17 07:34:23 +01:00
2021-09-23 21:18:44 +02:00
### Option 3 - from Node.js {#option-three---from-nodejs}
2021-02-25 16:01:36 +01:00
1. Create a new folder/directory on your development computer.
2. From a terminal/bash shell, install the dependencies:
2022-01-03 14:59:47 +01:00
```shell npm2yarn
2021-02-25 16:01:36 +01:00
npm init
npm install unleash-server --save
```
3. Create a file called _server.js_ , paste the following into it and save.
```js
const unleash = require('unleash-server');
unleash
.start({
2021-05-18 11:19:33 +02:00
db: {
ssl: false,
host: 'localhost',
port: 5432,
database: 'unleash',
user: 'unleash_user',
2022-01-24 09:27:50 +01:00
password: 'password',
2021-05-18 11:19:33 +02:00
},
server: {
port: 4242,
},
2021-02-25 16:01:36 +01:00
})
2021-11-23 09:43:35 +01:00
.then((unleash) => {
2021-02-25 16:01:36 +01:00
console.log(
`Unleash started on http://localhost:${unleash.app.get('port')}` ,
);
});
```
4. Run _server.js_ :
```sh
node server.js
```
2021-06-04 11:17:15 +02:00
## Create an api token for your client {#create-an-api-token-for-your-client}
2021-02-25 16:01:36 +01:00
refactor: move docs into new structure / fix links for SEO (#2416)
## What
This (admittedly massive) PR updates the "physical" documentation
structure and fixes url inconsistencies and SEO problems reported by
marketing. The main points are:
- remove or move directories : advanced, user_guide, deploy, api
- move the files contained within to the appropriate one of topics,
how-to, tutorials, or reference
- update internal doc links and product links to the content
- create client-side redirects for all the urls that have changed.
A number of the files have been renamed in small ways to better match
their url and to make them easier to find. Additionally, the top-level
api directory has been moved to /reference/api/legacy/unleash (see the
discussion points section for more on this).
## Why
When moving our doc structure to diataxis a while back, we left the
"physical' files lying where they were, because it didn't matter much to
the new structure. However, that did introduce some inconsistencies with
where you place docs and how we organize them.
There's also the discrepancies in whether urls us underscores or hyphens
(which isn't necessarily the same as their file name), which has been
annoying me for a while, but now has also been raised by marketing as an
issue in terms of SEO.
## Discussion points
The old, hand-written API docs have been moved from /api to
/reference/api/legacy/unleash. There _is_ a /reference/api/unleash
directory, but this is being populated by the OpenAPI plugin, and mixing
those could only cause trouble. However, I'm unsure about putting
/legacy/ in the title, because the API isn't legacy, the docs are. Maybe
we could use another path? Like /old-docs/ or something? I'd appreciate
some input on this.
2022-11-22 10:05:30 +01:00
- [API Token creation ](../../how-to/how-to-create-api-tokens.mdx )
2021-02-25 16:01:36 +01:00
2021-06-04 11:17:15 +02:00
## Test your server and create a sample API call {#test-your-server-and-create-a-sample-api-call}
2021-02-25 16:01:36 +01:00
2021-05-18 11:19:33 +02:00
Once the Unleash server has started, go to [localhost:4242 ](http://localhost:4242 ) in your browser. If you see an empty list of feature toggles, try creating one with [curl ](https://curl.se/ ) from a terminal/bash shell:
2021-02-25 16:01:36 +01:00
```
2021-06-04 13:44:34 +02:00
curl --location -H "Authorization: < apitoken from previous step > " \
--request POST 'http://localhost:4242/api/admin/features' \
--header 'Content-Type: application/json' --data-raw '{\
2021-02-25 16:01:36 +01:00
"name": "Feature.A",\
"description": "Dolor sit amet.",\
"type": "release",\
"enabled": false,\
"stale": false,\
"strategies": [\
{\
"name": "default",\
"parameters": {}\
}\
]\
2021-07-16 09:13:11 +02:00
}'
2021-02-25 16:01:36 +01:00
```
2021-06-04 11:17:15 +02:00
## Version check {#version-check}
2021-02-25 16:01:36 +01:00
- Unleash checks that it uses the latest version by making a call to https://version.unleash.run.
- This is a cloud function storing instance id to our database for statistics.
- This request includes a unique instance id for your server.
- If you do not wish to check for upgrades define the environment variable `CHECK_VERSION` to anything else other than `true` before starting, and Unleash won't make any calls
- `export CHECK_VERSION=false`