npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-runner-ts

v0.5.0

Published

Node runner is a powerful tool developed to optimize and speed up the process execution flow in your applications.

Downloads

18

Readme

NodeJs Runner Typescript

Description

Node runner is a powerful tool developed to optimize and speed up the process execution flow in your applications. It supports single, parallel and sequential execution, in addition to having a process orchestrator, ensuring efficient task management, high performance and scalability. Node Runner has a flexible, easy-to-integrate architecture that makes it the ideal choice for handling multiple operations, enabling your application to achieve higher levels of efficiency and responsiveness. Develop, execute and manage processes in an uncomplicated way.

Install

npm i node-runner-ts

Usage

Import the library in your code

import { Runner } from "node-runner-ts";

Create runner class

Customize your runner according to your needs, use the implementation of the RunnerType interface to define the mandatory methods, the class must be exported as standard, otherwise it will not be interpreted.

import { RunnerType } from "node-runner-ts";

export default class MyRunner implements RunnerType {
  async configure() {
    // Config dependencies
  }

  async run() {
    // Main logic to be executed when the executor is triggered.
  }
}

Runner methods

Exec

The Runner.exec method is designed to run a single specified process or module

import { Runner } from "node-runner-ts";

void Runner.exec({
  path: path.resolve(__dirname, "app", "server.runner.ts"),
  forever: true,
});

Parallelism

The Runner.parallelism method allows you to run multiple processes or modules simultaneously, improving efficiency and performance.

import { Runner } from "node-runner-ts";

void Runner.parallelism(
  {
    path: path.resolve(__dirname, "app", "server.runner.ts"),
    forever: true,
  },
  {
    path: path.resolve(__dirname, "worker", "worker.ts"),
    forever: false,
  }
);

Actions

Use a runner action to orchestrate and run your modules/processes.

Default

The default action orchestrator.

void Runner.runnerActions({
  test: {
    path: "./test/test.runner",
    forever: true,
  },
});

Parallelism

Have one or more actions run modules in parallel.

void Runner.runnerActions({
  server: {
    parallelism: [
      {
        path: "./app/run",
        forever: true,
      },
      {
        path: "./test/test.runner",
        forever: true,
      },
    ],
  },
});

Custom actions

Create your own orchestrator according to your needs.

import path from "node:path";
import { Runner, RunnerOptions } from "node-runner-ts";

export enum ActionType {
  Test = "Test",
  Server = "Server",
  MicroserviceEmail = "MicroserviceEmail",
  ApolloGraphql = "ApolloGraphql",
}

const OPTIONS: Record<string, RunnerOptions> = {
  [ActionType.ApolloGraphql]: {
    path: path.resolve(__dirname, "app", "graphql", "graphql.runner.ts"),
    forever: true,
  },
  [ActionType.MicroserviceEmail]: {
    path: path.resolve(__dirname, "microservice", "setup.ts"),
    forever: true,
  },
  [ActionType.Test]: {
    path: "./test/test-runner",
    forever: false,
  },
};

const customActions = async (action: ActionType): Promise<void> => {
  switch (action) {
    case ActionType.ApolloGraphql:
    case ActionType.MicroserviceEmail:
      return Runner.parallelism(
        OPTIONS[ActionType.ApolloGraphql],
        OPTIONS[ActionType.MicroserviceEmail]
      );
    default:
      return Runner.exec(OPTIONS[ActionType.Test]);
  }
};