Advanced
Methods to run your app locally

Ways to run your app locally

Running the server

To run the server locally, you can simply run

npx y-sweet serve

The following command will output a server token to run the client. When running locally, the server token is likely ys://127.0.0.1:8080

ℹ️

ys is simply a more secure protocol than http

Running the client

Running the client is as easy as running npm run dev.

But you can also add connection string as a parameter, which will set is an environment variable that you can use by importing it from a lib/config (opens in a new tab) like so:

import {CONNECTION_STRING} from '@/lib/config

In development, the connection string will be specified in the terminal out when you run the server. Usually, its ys://127.0.0.1:8080.

CONNECTION_STRING="ys://127.0.0.1:8080" npm run dev
ℹ️
  • if you don't specify a connection string, it will default to ys://127.0.1.8080

Specifying a data path

If you don't specify a data path, your data will be ephemeral. When you exit out of a doc and return, your data won't be persisted.

To persist data in a local environment, you can specify a data path like so:

CONNECTION_STRING=ys://127.0.1.8080 npm run dev ./data

Appending ./data will create a data folder in the root of your app. When user data is created, your data will be stored in the folder that you specified.

Testing multiplayer with y-sweet cloud

You can get a quickstart connection string on the y-sweet dashboard (opens in a new tab). If you haven't already, you can make an account here (opens in a new tab).

Then, set CONNECTION_STRING to your connection string.

CONNECTION_STRING=[YOUR_CONNECTION_STRING] npm run dev
ℹ️

You don't need to specify a data path, since your data will now be stored on y-sweet cloud.

y-sweet was created by Jamsocket.