Install

Manually

1. Clone the project

1npx degit Thomascogez/npflared/apps/api
INFO

You can also clone the project using git command but degit allow you to only retrieve the necessary parts

2. Install dependencies

After cloning the project you will need to install dependencies project using your favorite package manager

npm
yarn
pnpm
bun
1npm install
INFO

This project use pnpm as it dependencies manager

3. Configure project

In order to configure the project you will need to edit the wrangler.toml file

Configure your R2 bucket

Go to your Cloudflare Dashboard and create a new R2 bucket. Copy the name of your bucket and edit your wrangler.toml file

wrangler.toml
1[[r2_buckets]]
2binding = "BUCKET"
3bucket_name = "BUCKET_NAME" # Replace BUCKET_NAME with the value you have previously copied

Configure your D1 database

Go to your Cloudflare Dashboard and create a new D1 database. Copy the id and the name of your d1 database

wrangler.toml
1[[d1_databases]]
2binding = "DB"
3database_name = "D1_DATABASE_NAME" # Replace D1_DATABASE_NAME with the value you have previously copied
4database_id = "D1_DATABASE_ID" # Replace D1_DATABASE_ID with the value you have previously copied

4. Deploy your npflared worker

Once everything is set-up you can deploy your worker.

npm
yarn
pnpm
bun
1npm run deploy

5. Run initial migrations

Once your worker is deployed you have to run initial database migrations

npm
yarn
pnpm
bun
1npm run migrate:prod

6. Create your admin token

In order to distribute tokens for other users, you will need to create an initial token with elevated privileges

INFO

You can generate any kind of random values

Run the following command after replacing ADMIN_TOKEN with your desired token

1npx wrangler d1 execute DB --remote --yes --command "INSERT INTO token (token, name, scopes, created_at, updated_at) VALUES ('ADMIN_TOKEN', 'admin-token', '[{\"type\": \"token:read+write\", \"values\": [\"*\"]}, {\"type\": \"user:read+write\", \"values\": [\"*\"]}, {\"type\": \"package:read+write\", \"values\": [\"*\"]}]', 1734173399, 1734173399)"

And we are done 🎉