Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install - how to run build scripts with sufficient permissions?

Tags:

I've created a node-module that has a build script that gets called after the installation. The build script clones a git repository and copies some files of it to another folder. The problem: on npm install, the script does not get sufficient permissions and I get the following error:

sh: ./build.js: Permission denied

How can I give the build script sufficient permissions to do its job?

I want that the users just can do npm install mymodule and the build-script then does its job on any system.

Any ideas?

like image 453
Van Coding Avatar asked Feb 25 '13 10:02

Van Coding


People also ask

How do I run a script after npm install?

You can easily run scripts using npm by adding them to the "scripts" field in package. json and run them with npm run <script-name> . Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH , so you can run them by name instead of pointing to node_modules/.

How do I give npm permission?

Run “npm config get prefix” in your terminal. This will give the path of global node_modules: For ex: /usr/local. Change the user permissions for this folder by using following command: sudo chown -R <user_id> /usr/local/

Does npm install run build?

npm install installs dependencies into the node_modules/ directory, for the node project you're working on. You can call install on another node. js project (module), to install it as a dependency for your project. npm run build does nothing unless you specify what "build" does in your package.

How do I build a package using NPM?

npm build [< package-folder >] <package-folder>: A folder containing a package.json file in its root. Description. This is the plumbing command called by npm link and npm install. It should generally be called during installation, but if you need to run it directly, run: npm run-script build. See Also.

When does the NPM prepare script run?

These scripts happen in addtion to the "pre" and "post" script. NOTE: If a package being installed through git contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed. Runs BEFORE the package is prepared and packed, ONLY on npm publish.

Should I run tests before or after building with npm?

The neat thing about npm’s script commands is that we can automate tasks by prepending ‘pre’ or ‘post’ to them. So let’s make sure our tests always run before we build: Ok, so that’s a bit more fun. Of course, we need to do more with our code than test it.

Why use npm for building JavaScript applications?

While NPM is usually used for package installation with dependency management, we can also use it for building. This might seem kind of odd, using a package management tool for building our JavaScript applications, but I think it has some great advantages:


1 Answers

Do you have the x flag on build.js?

chmod +x build.js 

And the first line of your script should tell how to execute the script from the shell:

#!/usr/bin/env node 
like image 169
Pascal Belloncle Avatar answered Oct 27 '22 19:10

Pascal Belloncle