Skip to content

Latest commit

 

History

History
81 lines (62 loc) · 2.61 KB

README.md

File metadata and controls

81 lines (62 loc) · 2.61 KB

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