1
Install the SDK
2
Add your keys
Set your project’s API key and secret as environment variables wherever your app runs:The SDK reads both values from
.env
process.env. Node.js doesn’t load .env on its own: start your app with node --env-file=.env, or set the variables in your host’s settings. The API key lets your app start runs and save steps. The secret lets your app check that each call really comes from Nelkap.3
Create your client and your first workflow
Create
src/nelkap.ts:src/nelkap.ts
onboardUseris your workflow: an async function that takes the run’s payload, here a user ID.- Each
step.runsaves what its function returns. When the run picks up after the sleep, the profile step gives back its saved result instead of creating the profile again. step.sleeppauses the run for a day. Nothing runs in your app during that day.registerWorkflowstells Nelkap which workflows your app runs, as soon as the file is loaded.
createProfile and sendWelcomeEmail with your own functions.4
Add the route Nelkap calls
nelkap.handle takes a standard web Request, while Express gives you its own request object. The route below builds a standard Request from it, passes it to handle, and sends back the answer:src/index.ts
- The request’s body streams straight into
handle, so a run with many saved steps isn’t held back by a body size limit. - Add this route before
app.use(express.json()). Otherwise Express reads the body first, andhandlegets an empty one. handlechecks the secret, answers Nelkap at once, and runs the workflow in the background. Your server keeps running after the answer, so the run goes on until it completes or pauses.
/api/nelkap out: handle checks Nelkap’s secret instead.5
Deploy and set your endpoint
Deploy your app, so Nelkap can reach the route over the internet. Then edit your project and set its endpoint to the route’s URL, like
https://your-app.com/api/nelkap.6
Start a run
Start the workflow from any route of your app. Here, a sign-up route starts it once the user is created:
src/index.ts
run returns as soon as Nelkap has the run, so the sign-up doesn’t wait for the workflow. Its second argument, user.id, is the run’s payload: Nelkap passes it to onboardUser.7
Follow your run
Open your project’s runs. The new run shows the profile step with what it returned, then sleeps. A day later, Nelkap calls your route again, the welcome email goes out, and the run completes.