Abort npm build script from node.js scriptHow do I remove a property from a JavaScript object?How do I pass command line arguments to a Node.js program?How to decide when to use Node.js?How to exit in Node.jsHow do I remove a particular element from an array in JavaScript?How can I update NodeJS and NPM to the next versions?Find the version of an installed npm packageWhat is the difference between Bower and npm?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What is the --save option for npm install?

Increase performance creating Mandelbrot set in python

Valid Badminton Score?

Go Pregnant or Go Home

How do I rename a LINUX host without needing to reboot for the rename to take effect?

Can criminal fraud exist without damages?

How can a jailer prevent the Forge Cleric's Artisan's Blessing from being used?

Do I need a multiple entry visa for a trip UK -> Sweden -> UK?

There is only s̶i̶x̶t̶y one place he can be

Print name if parameter passed to function

Why are on-board computers allowed to change controls without notifying the pilots?

Will it be accepted, if there is no ''Main Character" stereotype?

Is exact Kanji stroke length important?

How does it work when somebody invests in my business?

Finding all intervals that match predicate in vector

Coordinate position not precise

Cynical novel that describes an America ruled by the media, arms manufacturers, and ethnic figureheads

Is the destination of a commercial flight important for the pilot?

Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?

Is there a good way to store credentials outside of a password manager?

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

What would be the benefits of having both a state and local currencies?

when is out of tune ok?

Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?

What defines a dissertation?



Abort npm build script from node.js script


How do I remove a property from a JavaScript object?How do I pass command line arguments to a Node.js program?How to decide when to use Node.js?How to exit in Node.jsHow do I remove a particular element from an array in JavaScript?How can I update NodeJS and NPM to the next versions?Find the version of an installed npm packageWhat is the difference between Bower and npm?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What is the --save option for npm install?













2















I created a node script which checks if my project contains lock file or not. If it doesn't then I want to abort my npm build. Any idea how to do that?



lock-check.js



const path = require('path');
const fs = require("fs");

const lockFiles = ["package-lock.json", "npm-shrinkwrap.json", "yarn.lock"];

let exists = 0;

function checkIfExists()
lockFiles.forEach(
(lf) =>
if (fs.existsSync(lf))
exists++;

);

return exists > 0;



package.json



...

"scripts":
"prestart": "node ./lock-check.js" // Abort the task
"start": "webpack-dev-server --config config/webpack.dev.js --hot --inline"


...









share|improve this question






















  • to abort you can do process.exit(1) with 1 or any non zero exit code to tell it was not completed successfully

    – warl0ck
    Mar 8 at 9:40












  • I suspect that would work. npm is a different process so it will resume execution.

    – Neptune
    Mar 8 at 9:41











  • it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero

    – warl0ck
    Mar 8 at 9:43






  • 1





    Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that

    – Neptune
    Mar 8 at 9:46












  • It's working. Thanks

    – Gabriel
    Mar 8 at 9:47















2















I created a node script which checks if my project contains lock file or not. If it doesn't then I want to abort my npm build. Any idea how to do that?



lock-check.js



const path = require('path');
const fs = require("fs");

const lockFiles = ["package-lock.json", "npm-shrinkwrap.json", "yarn.lock"];

let exists = 0;

function checkIfExists()
lockFiles.forEach(
(lf) =>
if (fs.existsSync(lf))
exists++;

);

return exists > 0;



package.json



...

"scripts":
"prestart": "node ./lock-check.js" // Abort the task
"start": "webpack-dev-server --config config/webpack.dev.js --hot --inline"


...









share|improve this question






















  • to abort you can do process.exit(1) with 1 or any non zero exit code to tell it was not completed successfully

    – warl0ck
    Mar 8 at 9:40












  • I suspect that would work. npm is a different process so it will resume execution.

    – Neptune
    Mar 8 at 9:41











  • it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero

    – warl0ck
    Mar 8 at 9:43






  • 1





    Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that

    – Neptune
    Mar 8 at 9:46












  • It's working. Thanks

    – Gabriel
    Mar 8 at 9:47













2












2








2








I created a node script which checks if my project contains lock file or not. If it doesn't then I want to abort my npm build. Any idea how to do that?



lock-check.js



const path = require('path');
const fs = require("fs");

const lockFiles = ["package-lock.json", "npm-shrinkwrap.json", "yarn.lock"];

let exists = 0;

function checkIfExists()
lockFiles.forEach(
(lf) =>
if (fs.existsSync(lf))
exists++;

);

return exists > 0;



package.json



...

"scripts":
"prestart": "node ./lock-check.js" // Abort the task
"start": "webpack-dev-server --config config/webpack.dev.js --hot --inline"


...









share|improve this question














I created a node script which checks if my project contains lock file or not. If it doesn't then I want to abort my npm build. Any idea how to do that?



lock-check.js



const path = require('path');
const fs = require("fs");

const lockFiles = ["package-lock.json", "npm-shrinkwrap.json", "yarn.lock"];

let exists = 0;

function checkIfExists()
lockFiles.forEach(
(lf) =>
if (fs.existsSync(lf))
exists++;

);

return exists > 0;



package.json



...

"scripts":
"prestart": "node ./lock-check.js" // Abort the task
"start": "webpack-dev-server --config config/webpack.dev.js --hot --inline"


...






javascript node.js npm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 9:35









GabrielGabriel

1,56142749




1,56142749












  • to abort you can do process.exit(1) with 1 or any non zero exit code to tell it was not completed successfully

    – warl0ck
    Mar 8 at 9:40












  • I suspect that would work. npm is a different process so it will resume execution.

    – Neptune
    Mar 8 at 9:41











  • it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero

    – warl0ck
    Mar 8 at 9:43






  • 1





    Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that

    – Neptune
    Mar 8 at 9:46












  • It's working. Thanks

    – Gabriel
    Mar 8 at 9:47

















  • to abort you can do process.exit(1) with 1 or any non zero exit code to tell it was not completed successfully

    – warl0ck
    Mar 8 at 9:40












  • I suspect that would work. npm is a different process so it will resume execution.

    – Neptune
    Mar 8 at 9:41











  • it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero

    – warl0ck
    Mar 8 at 9:43






  • 1





    Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that

    – Neptune
    Mar 8 at 9:46












  • It's working. Thanks

    – Gabriel
    Mar 8 at 9:47
















to abort you can do process.exit(1) with 1 or any non zero exit code to tell it was not completed successfully

– warl0ck
Mar 8 at 9:40






to abort you can do process.exit(1) with 1 or any non zero exit code to tell it was not completed successfully

– warl0ck
Mar 8 at 9:40














I suspect that would work. npm is a different process so it will resume execution.

– Neptune
Mar 8 at 9:41





I suspect that would work. npm is a different process so it will resume execution.

– Neptune
Mar 8 at 9:41













it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero

– warl0ck
Mar 8 at 9:43





it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero

– warl0ck
Mar 8 at 9:43




1




1





Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that

– Neptune
Mar 8 at 9:46






Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that

– Neptune
Mar 8 at 9:46














It's working. Thanks

– Gabriel
Mar 8 at 9:47





It's working. Thanks

– Gabriel
Mar 8 at 9:47












1 Answer
1






active

oldest

votes


















1














To abort the build process you just have to call process.exit(1),



Here I have used 1 but you can use any non-zero exit code to tell it wasn't a successful build as 0 means successful.



You can read more on official nodejs docs






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060371%2fabort-npm-build-script-from-node-js-script%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    To abort the build process you just have to call process.exit(1),



    Here I have used 1 but you can use any non-zero exit code to tell it wasn't a successful build as 0 means successful.



    You can read more on official nodejs docs






    share|improve this answer



























      1














      To abort the build process you just have to call process.exit(1),



      Here I have used 1 but you can use any non-zero exit code to tell it wasn't a successful build as 0 means successful.



      You can read more on official nodejs docs






      share|improve this answer

























        1












        1








        1







        To abort the build process you just have to call process.exit(1),



        Here I have used 1 but you can use any non-zero exit code to tell it wasn't a successful build as 0 means successful.



        You can read more on official nodejs docs






        share|improve this answer













        To abort the build process you just have to call process.exit(1),



        Here I have used 1 but you can use any non-zero exit code to tell it wasn't a successful build as 0 means successful.



        You can read more on official nodejs docs







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 9:46









        warl0ckwarl0ck

        1,72011632




        1,72011632





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060371%2fabort-npm-build-script-from-node-js-script%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived