Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node_modules-path

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node_modules-path

Get the path of the `node_modules` folder in your scripts or CLI or package.json

  • 2.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.7K
decreased by-1.72%
Maintainers
1
Weekly downloads
 
Created
Source

Get the path of the node_modules folder in your scripts or CLI or package.json. This is useful when you are building a library that can either be used as an npm dependency or directly, see this question on SO.

You can add a parameter in order to look for a specific module. This is useful when npm creates multiple node_modules folder for conflicts reasons.

Installation

$ npm install node_modules-path --save

Test

$ npm test

This project has been battle tested on Silex website builder

Access node_modules in package.json

Use it in your packge.json like this:

"name": "my-super-project",
"scripts": {
  "build": "cp -R `node_modules`/font-awesome/fonts/* dist/fonts/", <=== this will be executed as cp -R /path-to-your-node_modules/or-the-node_modules-of-a-parent/font-awesome/fonts/* dist/fonts/

With a specific module name as a param:

"scripts": {
  "test": "echo  `node_modules` can differ from `node_modules module1`", <=== this will be executed as cp -R /path-to-your-node_modules/or-the-node_modules-of-a-parent/font-awesome/fonts/* dist/fonts/

node_modules folder path from another nodejs script

const node_modules = require('node_modules-path');
console.log('node module path for this project:', node_modules());

This is especially useful to serve fonts in an express app

app.use('/fonts', express.static(Path.resolve(node_modules(), 'font-awesome/fonts/')));
// node_modules() will return the path to your node_modules or to the node_modules of a parent

With a specific module name as a param, which is safer:

app.use('/fonts', express.static(Path.resolve(node_modules('font-awesome'), 'font-awesome/fonts/')));
// node_modules('font-awesome') will return the path to your node_modules or to the node_modules of a parent

node_modules folder path for sass includes

In your package.json script to compile sass:

{
    "build:sass": "sass --load-path `node_modules normalize.css` src/css/app.scss dist/css/app.css"
}

Keywords

FAQs

Package last updated on 02 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc