Express.js and Taskless
The express.js integration is available via the npm package @taskless/express
and follows the standard createQueue convention. The returned object is both a Taskless aware API as well as an object capable of exporting an Express.Router
for use in your express.js apps.
1function createQueue<T>(2 queueName: string,3 path: string,4 handler: JobHandler<T>,5 queueOptions?: QueueOptions6): TasklessExpressRouter<T>;78interface JobHandler<T> {9 (payload: T, meta: JobMetadata): Promised<unknown>;10}1112interface TasklessExpressRouter<T> extends QueueMethods<T> {13 router: (mount?: string) => express.Router;14}
Express Specific Methods
router(mount?: string): express.Router
Create an Express Router, optionally mounted to the subroute path of mount
. In larger Express apps, it is common to nest routers as a form of code organization. When Taskless queues are not being mounted to the application root via app.use()
, it is necessary to tell Taskless where its queue was placed. The mount
argument lets you specify a full mount location for the Taskless Router. Without this information, Taskless cannot construct a proper URL during enqueue()
that will end up back at your Job handler.