### Install and Run Puter Locally Source: https://github.com/heyputer/puter/wiki/_Footer Clone the Puter repository, install dependencies, and start the development server. ```sh git clone https://github.com/HeyPuter/puter.git npm install npm run start ``` -------------------------------- ### Install and Run Locally Source: https://github.com/heyputer/puter/blob/main/src/mcp-connector/README.md Installs dependencies and starts the development server for the MCP connector. This command builds the project and then launches it using Wrangler. ```bash cd src/mcp-connector npm install npm run dev # builds, then wrangler dev — serves on http://localhost:8787 ``` -------------------------------- ### Clone and Start Puter Locally Source: https://github.com/heyputer/puter/blob/main/README.md Clone the Puter repository, install dependencies, and start the local development server. This command sequence is used for setting up Puter on a local machine for development purposes. ```bash git clone https://github.com/HeyPuter/puter cd puter npm install npm start ``` -------------------------------- ### Get a subdomain Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Hosting/get.md This example demonstrates how to create a website, retrieve its details using `puter.hosting.get()`, and then clean up by deleting the website. Ensure the Puter SDK is loaded before executing. ```html
``` -------------------------------- ### Create and Get an App Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Apps/get.md This example demonstrates how to create a random app, retrieve its details using `puter.apps.get()`, and then clean up by deleting the app. Ensure the Puter JS SDK is included. ```html ``` -------------------------------- ### Example: Create an app pointing to example.com Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Apps/create.md This example demonstrates how to create a new Puter app using `puter.apps.create()`, assign it a URL, and then clean up by deleting it. ```APIDOC ## Example: Create an app pointing to example.com Create an app pointing to example.com ```html;app-create ``` ``` -------------------------------- ### Create, Get, and Delete an App with Puter SDK Source: https://github.com/heyputer/puter/blob/main/src/docs/src/playground/examples/app-get.html This example shows how to create a new application, retrieve it using its name, and then delete it. Ensure you have the Puter SDK initialized before running this code. ```javascript (async () => { // (1) Generate a random app name to make sure it doesn't already exist let appName = puter.randName(); // (2) Create the app await puter.apps.create(appName, "https://example.com"); puter.print(`"${appName}" created
```
--------------------------------
### Start Puter Desktop
Source: https://github.com/heyputer/puter/blob/main/src/puter-js/TESTING.md
Run this command from the monorepo root to start the Puter desktop application. It will print default login credentials on first launch.
```sh
cd /path/to/puter
npm start
```
--------------------------------
### Complete Worker Deployment and Testing Example
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Workers/create.md
This example demonstrates the full lifecycle: writing worker code to a file, deploying the worker using puter.workers.create(), and then testing it after a short propagation delay. Ensure the worker code is saved to 'my-worker.js' before deployment.
```html
```
--------------------------------
### Install Puter.js NPM Library
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/frameworks.md
Install the Puter.js NPM library using npm.
```bash
npm install @heyputer/puter.js
```
--------------------------------
### Example: Requesting and Using Documents Write Access
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Perms/requestWriteDocuments.md
This example demonstrates how to request write access to the Documents folder and then write a file to it. It includes basic error handling for denied access.
```html
```
--------------------------------
### Puter-JS End-to-End Test Setup and Execution
Source: https://github.com/heyputer/puter/blob/main/src/puter-js/tests/e2e/README.md
This snippet shows the essential commands for setting up and running end-to-end tests. It includes one-time setup for environment variables and commands for running tests in headless, headed, and recording modes.
```sh
# one-time setup
cp tests/e2e/.env.example tests/e2e/.env
$EDITOR tests/e2e/.env # set PUTER_ADMIN_PASSWORD from the npm start banner
# run
npm run test:e2e # headless
npm run test:e2e:headed # watch the browser
npm run test:e2e:record # save video for every test
```
--------------------------------
### Example: Sign Out User in HTML
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Auth/signOut.md
This HTML example demonstrates how to include the Puter SDK and call the signOut() function within a script tag.
```html
```
--------------------------------
### Start puter-js Dev Server
Source: https://github.com/heyputer/puter/blob/main/src/puter-js/TESTING.md
Execute this command from the src/puter-js directory to start the puter-js development server, which serves necessary files for testing on localhost:8080.
```sh
cd /path/to/puter/src/puter-js
npm start
```
--------------------------------
### Start Puter with Docker Compose
Source: https://github.com/heyputer/puter/blob/main/doc/self-hosting.md
Bring up the Puter application and its services using Docker Compose. This command starts all defined services in detached mode.
```bash
docker compose up -d
```
--------------------------------
### Create a simple website displaying "Hello world!"
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Hosting/create.md
This example demonstrates how to create a random directory, write an 'index.html' file with "Hello, world!" content into it, and then host this directory under a random subdomain. It utilizes `puter.randName()`, `puter.fs.mkdir()`, `puter.fs.write()`, and `puter.hosting.create()`.
```html
```
--------------------------------
### Create an app pointing to example.com
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Apps/create.md
This example demonstrates creating a Puter app with a specified name and index URL. It includes cleanup by deleting the app after creation. Ensure the Puter SDK is loaded before executing.
```html
```
--------------------------------
### Complete Worker Router Example
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Workers/router.md
This snippet shows a comprehensive worker setup with multiple endpoints for health checks, user management, file uploads, and a catch-all 404 handler. It demonstrates GET and POST requests, parameter extraction, KV and FS interactions, and custom response handling.
```javascript
// Health check
router.get("/health", async () => {
return {
status: "ok",
timestamp: new Date().toISOString(),
};
});
// User management API
router.post("/api/users", async ({ request, user }) => {
const userInfo = await user.puter.getUser();
// Store user data
const userId = `user_${Date.now()}`;
await me.puter.kv.set(userId, {
email: userInfo.email,
name: userInfo.username,
});
return {
userId,
user: {
email: userInfo.email,
username: userInfo.username,
uuid: userInfo.uuid,
},
};
});
router.get("/api/users/:id", async ({ params }) => {
const userId = params.id;
if (!userId.startsWith("user_"))
// security check
return new Response("Invalid userID!");
const userData = await me.puter.kv.get(userId);
if (!userData) {
return new Response(
JSON.stringify({
error: "User not found",
}),
{
status: 404,
headers: { "Content-Type": "application/json" },
}
);
}
return { userId, user: userData };
});
// File operations
router.post("/api/files/upload", async ({ request }) => {
const formData = await request.formData();
const file = formData.get("file");
if (!file) {
return new Response(
JSON.stringify({
error: "No file provided",
}),
{
status: 400,
headers: { "Content-Type": "application/json" },
}
);
}
const fileName = `upload-${Date.now()}-${file.name}`;
await me.puter.fs.write(fileName, file);
return {
uploaded: true,
fileName,
originalName: file.name,
size: file.size,
};
});
// 404 handler
router.get("/*tag", async ({ params }) => {
return new Response(
JSON.stringify({
error: "Not found",
path: params.tag,
availableEndpoints: ["/health", "/api/users", "/api/files/upload"],
}),
{
status: 404,
headers: { "Content-Type": "application/json" },
}
);
});
```
--------------------------------
### Install Base Development Packages on Arch Linux
Source: https://github.com/heyputer/puter/wiki/self_hosters-first_run_issues
Install the 'base-devel' package group on Arch Linux to get the necessary build tools.
```bash
sudo pacman -S base-devel
```
--------------------------------
### Create and list websites
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Hosting/list.md
This example demonstrates creating three random websites, listing them using `puter.hosting.list()`, displaying their subdomains, and then cleaning up by deleting the created sites.
```html
```
--------------------------------
### Get a subdomain
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Hosting.md
This example shows how to retrieve information about a specific subdomain, including its UID. It first creates a website and then uses the get() method to fetch its details.
```APIDOC
## GET /hosting/get
### Description
Retrieves information about a specific hosting deployment (subdomain).
### Method
GET
### Endpoint
/hosting/get
### Parameters
#### Query Parameters
- **subdomain** (string) - Required - The subdomain to retrieve information for.
### Response
#### Success Response (200)
- **subdomain** (string) - The subdomain name.
- **uid** (string) - The unique identifier for the hosting deployment.
```
--------------------------------
### One-line Installer for Puter
Source: https://github.com/heyputer/puter/blob/main/doc/self-hosting.md
This command downloads and executes the official Puter installation script. It automates the generation of secrets, configuration file setup, and Docker Compose deployment.
```bash
curl -fsSL https://raw.githubusercontent.com/HeyPuter/puter/main/install.sh | sh
```
--------------------------------
### Create a new file with 'Hello, world!'
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/FS/write.md
Use this snippet to create a new text file with specific content. Ensure the Puter SDK is included.
```html
```
--------------------------------
### Defining a Custom Puter Kernel Module
Source: https://github.com/heyputer/puter/wiki/backend-contributors-modules
Example of a custom module extending `AdvancedBase` and implementing the `install` method to register new services. The `install` method receives a `Context` object, which provides access to the services container.
```javascript
class MyPuterModule extends AdvancedBase {
async install (context) {
const services = context.get('services');
const MyService = require('./path/to/MyService.js');
services.registerService('my-service', MyService, {
some_options: 'for-my-service',
});
}
}
```
--------------------------------
### Read File Example
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/playground/examples/fs-read.html
Use `puter.fs.read` to get the content of a file as a Blob. Then, convert the Blob to text using `.text()`.
```javascript
(async () => {
// (1) Create a random text file
let filename = puter.randName() + ".txt";
await puter.fs.write(filename, "Hello world! I'm a file!");
puter.print(`"${filename}" created` and `` tags.
```APIDOC
## Example: Print "Hello, world!" as code
```html
```
```
--------------------------------
### List keys matching a pattern
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/KV/list.md
Provide a string pattern to filter keys. The pattern supports a wildcard '*' only at the end for prefix matching. For example, 'abc*' matches keys starting with 'abc'.
```javascript
puter.kv.list(pattern)
```
--------------------------------
### Get Paginated List of App Users
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/Objects/app.md
Use the `getUsers()` method to retrieve a paginated list of users for an app. You can specify `limit` and `offset` to control the number of users and the starting point of the retrieval.
```html
```
--------------------------------
### Create and Delete an App
Source: https://github.com/heyputer/puter/blob/main/src/docs/src/playground/examples/app-delete.html
This example shows the full lifecycle of an app: creation, deletion, and then attempting to retrieve it to confirm deletion. It uses `puter.randName()` to ensure a unique name for the app before creation.
```javascript
(async () => {
// (1) Generate a random app name to make sure it doesn't already exist
let appName = puter.randName();
// (2) Create the app
await puter.apps.create(appName, "https://example.com");
puter.print(`"${appName}" created
`);
// (3) Delete the app
await puter.apps.delete(appName);
puter.print(`"${appName}" deleted
`);
// (4) Try to retrieve the app (should fail)
puter.print(`Trying to retrieve "${appName}"...
`);
try {
await puter.apps.get(appName);
} catch (e) {
puter.print(`"${appName}" could not be retrieved
`);
}
})();
```