Skip to content

A function to terminate Node.js processes with an error and a non-zero exit code

License

Notifications You must be signed in to change notification settings

ChristianGrete/exit-process-with-error

Repository files navigation

License: MIT Language: TypeScript Latest Build

A function to terminate Node.js processes with an error and a non-zero exit code

Getting started

Installation

To install this package to your Node.js modules, run:

npm i -S exit-process-with-error

Or, using Yarn, run:

yarn add exit-process-with-error

Usage

Simply import it as an ES2015 module and terminate 💥 your process:

import exitProcessWithError from 'exit-process-with-error'

exitProcessWithError() // Boom!

Example

Let’s assume that we want to read a corrupted file using Promise:

import {readFile} from 'fs'
import {exitProcessWithError} from 'exit-process-with-error'

const whenFileRead = new Promise(($resolve, $reject) => {
  readFile('corrupted-file.txt', ($error, $data) => {
    if ($error === null) {
      $resolve($data)
    } else {
      $error.exitCode = $error.exitCode || 123

      $reject($error)
    }
  })
})

whenFileRead
  .then(console.log) // Won’t be invoked
  .catch(exitProcessWithError)

// Prints the error object and
// terminates the process with exit code 123

Contributing

If you want to contribute as a developer, see the contribution guidelines on how to get involved with this project.

License

This software is licensed under MIT License.


Copyright © 2018 Christian Grete

About

A function to terminate Node.js processes with an error and a non-zero exit code

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published