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 πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

simplejob

v0.3.5

Published

A tool class to wrap your jobs/scripts and easily get logs and reports like πŸ‘‡

Downloads

286

Readme

simplejob

A tool class to wrap your jobs/scripts and easily get logs and reports like πŸ‘‡

[12:11:49] πŸš€ Job started...
[12:11:49] Error on user [42]
[12:11:49] Error while fetching date
[12:11:49] βœ… Job done.
+------------------- Job report ---------------------+
πŸ‘· Job >  testJob
πŸ“ Path > /Users/alex/Documents/perso/simplelogs-package/src/testJob.ts
🚦 Status >  warning
⏰ Duration >  0.004s
πŸ’¬ Args >
        - startDate: "2021-10-10"
        - endDate: "2023-10-10"
πŸ“Š Results >
        - notificationSent: 42
🚩 Errors >
        - Error on user [42]
        - Error while fetching date
+------------------------------------------------------+

Installaton

yarn add simplejob
# or
npm i -S simplejob
import { SimpleJob, JobStatus } from "simplejob";

class MyJob extends SimpleJob {
  connect = async () => {
    // your database connection
  };

  disconnect = async () => {
    // your database connection
  };

  onEnd = async (status: JobStatus, crashError?: any) => {
    // your custom actions
  };
}

Usage

Create your job

const job = new MyJob({
  maintainer: "John Doe",
  filename: __filename,
});

job.start(async () => {
  // Your job operations...
});

Adding results/errors/logs

job.addResult("userMigrated"); // Adding 1 result.
job.addResult("userMigrated", 42); // Adding 42 results.

job.addError(`Error on user ${user.id}`, { userId: user.id }); // Adding an error with data.

job.addLog(`${user.id} migrated`);

Getting args

getArgs helps you getting args params, logging errors and usage using Joi.

const args = job.getArgs<{
  country: "france" | "usa";
  city?: string;
  confirm?: boolean;
}>(
  {
    country: Joi.string().valid("usa").valid("france").required(),
    city: Joi.string(),
  },
  {
    confirm: Joi.boolean(),
  }
);

will log

> node myjob germany orleans
"country" is invalid
Usage: "node myjob <country> [city] [--confirm]"

πŸ’‘ Note: for now, compatible Joi package is "17.4.0"

Exporting csv

await job.exportCsv(`${__dirname}/data/user_data.csv`, [
  { id: 1, name: "John" },
  { id: 2, name: "Jane" },
]);

Will write a csv file using writeStream (create path if it doesn't exist).

Incoming...

This package doc and Class is still in construction, some features are coming in next versions! fork children, getArgs without Joi, exportJson, saveReport, customizations...

API

🚧 In construction...

SimpleJob Class api

| property | description | type | default | | ------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ---------------------- | | connect | Connect function called before job execution | async () => void | | | disconnect | Disconnect function called after the job execution | async () => void | | | onEnd | Function called after the job execution | async (status: JobStatus, crashError?: any) => void | | | start | Start | async (async () => any) => void | | | status | Actual status of the job instance | 'pending' | 'running' | 'warning' | 'success' | 'error' | 'exit' | 'pending' | | timeformat | Format of time to be displayed in logs | dayjs format | 'hh:mm:ss' | | env | Environment of the job | string | undefined | process.env.NODE_ENV | | getArgs | Get args and return an object of it | (params, namedParams) => object | function | | exportCsv | Export csv data in a file (create dir) | (path, data) => void | function | | addError | Add an error | (message: string, data: any) => void | function | | addLog | Add a log | (message: string, data: any) => void | function | | args | Arguments object filled with .getArgs | object | {} | | logs | Logs filled with .addError and .addLog | JobLog[] | [] | | results | Results filled with .addResult | JobResult[] | [] | | reportErrorsLimit | Limit of errors to be displayed in the report | number | 6 | | disableReport | Disable the report at the end of the job | boolean | false | | disableConnect | Disable the connect/disconnect methods at the start/end of the job | boolean | false | | maintainer | Name of the maintainer | string | undefined | | | scriptName | Name of the file (deducted from constructor option filename) | string | | | scriptPath | Full path (equal from constructor option filename) | string | | | description | Description of the job | string | | | maintainer | name of the author/maintainer | string | | | startedAt | Date of the start of the job | Date | | | endedAt | Date of the end of the job | Date | | | startedAtTimestamp | Timestamp of the start of the job | number | | | endedAtTimestamp | Timestamp of the end of the job | number | | | simplelogsToken | Token to be used to send logs to simplelogs (incoming) | string | undefined | | | tags | Tags to be used to send logs to simplelogs (incoming) | string[] | undefined | | | thread | Thread for simplelogs app (incoming) | string | |

SimpleJob constructor options

Options used with constructor call πŸ‘‰ const job = new SimpleJob(options)

| property | description | type | required | | -------- | ------------------------------------ | -------- | -------- | | filename | Full path of the file (__filename) | string | [x] |