A function to terminate Node.js processes with an error and a non-zero exit code
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
Simply import it as an ES2015 module and terminate 💥 your process:
import exitProcessWithError from 'exit-process-with-error'
exitProcessWithError() // Boom!
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
If you want to contribute as a developer, see the contribution guidelines on how to get involved with this project.
This software is licensed under MIT License.
Copyright © 2018 Christian Grete