Temporal NodeJS SDK
Typescript + NodeJS SDK for Temporal.
!!! This is a work in progress, not ready for use yet !!!
For more information see the proposal.
Getting started
Not working yet, activities not implemented
Install system dependencies
This project requires nodejs LTS version 12 (or later).
Furthermore, to install this module you will need a c++ compiler and the Rust toolchain installed.
If you run into errors during installation it is likely your environment is not properly set up.
- To set up a C++ compiler for
node-gyp
, follow the instuctions here - To set up the Rust toolchain, follow the instruction here
Create a new project
npm init @temporalio ./example
cd ./example
Build everything
npm run build
Run the Temporal server
Download, install, and run the Temporal server via docker-compose. It is easy to do and you can keep it running in the background while you build applications.
Test your workflow
-
Run the worker
node lib/worker/index.js
-
Run the workflow
node lib/worker/test.js
Hello World
Activities and workflows
src/activities/greeter.ts
export async function greet(name: string): Promise<string> {
return `Hello, ${name}!`;
}
src/interfaces/workflows.ts
import { Workflow } from '@temporalio/workflow';
export interface Example extends Workflow {
main(name: string): Promise<string>;
}
src/workflows/example.ts
import { Example } from '@interfaces/workflows';
import { greet } from '@activities/greeter';
async function main(name: string): Promise<string> {
return await greet(name);
}
export const workflow: Example = { main };
Worker and client
src/worker/index.ts
import { Worker } from '@temporalio/worker';
(async () => {
const worker = new Worker(__dirname);
await worker.run('tutorial');
})();
src/worker/test.ts
import { Connection } from '@temporalio/client';
import { Example } from '@interfaces/workflows';
(async () => {
const connection = new Connection();
const example = connection.workflow<Example>('example', { taskQueue: 'tutorial' });
const result = await example('Temporal');
console.log(result);
})();
Development
Environment set up
git submodule init
git submodule update
npm ci
Building
npm run clean
npm run build
Building with watch
npm run clean
npm run build
npm run build.watch
Testing
npm run test
-- OR --
npm run test.watch