Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:53:03+00:00 2026-06-17T22:53:03+00:00

How to install npm package from nodejs script? Question is not about simple installation

  • 0

How to install npm package from nodejs script?

Question is not about simple installation npm packages via terminal,
it is about installation via nodejs script:
Not about this: npm install express, but about having install.js file with content npm install express, which I will execute like node install.js and after this it will locally install express module in this folder.

Sorry, but Google and DuckDuckGo are not my friends today(

The main problem is in automatic local installation required packages for my small utility, because global packages are not working in windows.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:53:05+00:00Added an answer on June 17, 2026 at 10:53 pm

    Check out commander.js it allows you to write command line apps using node.

    Then you can use the exec module.

    Assuming you put the following in install.js, you just have to do: ./install.js and it will run npm install for you.

    #!/usr/bin/env node
    
    var program = require('commander');
    var exec = require('child_process').exec;
    
    var run = function(cmd){
      var child = exec(cmd, function (error, stdout, stderr) {
        if (stderr !== null) {
          console.log('' + stderr);
        }
        if (stdout !== null) {
          console.log('' + stdout);
        }
        if (error !== null) {
          console.log('' + error);
        }
      });
    };
    
    program
      .version('0.1.3')
      .option('i, --install ', 'install packages')
      .parse(process.argv);
    
    
    
    if (program.install) {
      run('npm install');
    }
    
    
    var count = 0;
    
    
    // If parameter is missing or not supported, display help
    program.options.filter(function (option) {
      if(!(option.short == process.argv[2]))
        count++
    });
    
    if(count == program.options.length)
      program.help();
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully a simple question, npm install http works fine and I can connect via
Locally, I can run: npm install oscar@0.2.0 To install this package: https://npmjs.org/package/oscar And you
I've installed nodeJS ( from http://nodejs.org/ ). This has installed nodeJS & npm. Then
I'm trying to install NPM packages on Ubuntu (12.04). I've installed Node.js and NPM
I'm trying to get npm to install node-gitteh as a dependency via npm install
I've repeated steps from batman.js readme : npm install -g batman batman new mj
I'm trying to install Meteor package manager - Meteorite. When I do npm install
Is there a way to override npm's version checking against a packages.json file from
I used npm to install socket.io. The server is running fine but is not
How can I make so npm install package will only install the package if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.