March 5, 2018

Throwing Errors in Npm Build Script

From time to time you may want to throw an error from within an npm build script. This should be done in such a way that the complete execution of the script is recognized as faulty. So that for example, a build server recognizes that a script did not run successfully. You only need to output the correct exit code in order to achieve this behaviour. Ideally, the user should also receive an error message that is as accurate as possible.

Lets take a look at the code:

 

 

 

All we do is to echo some text and then we append ‘exit 1’ which indicates unsuccessful termination. Thats it.

Related Posts

Admin Admin
Developer at thecodecampus </>


Leave a Reply

Add code to your comment in Markdown syntax.
Like this:
`inline example`

```
code block
example
```

Your email address will not be published.