Tips for developing an npm package that includes a demonstration application

When creating packages, I believe it's important to include a demo app. However, I'm unsure about the best way to organize the file structure for this purpose.

My goal is to have one Github repository containing both my published NPM module and a simple demo webapp.

Ideally, I would like to have a top-level structure like this:

package/
demo/

Where only the code inside the package/ directory gets distributed to NPM. I could use the files: ['package'] option in the package.json file, but then all the code will have that path prefix, such as:

node_modules/MyPackageName/package/index.js

Is there a way to modify the path prefix so that it changes the top-level directory and removes the extra package/ used for organizing the files?

I know some people might have solutions for this, but I'd prefer not to have two separate repositories - one for the demo and one for the package.

Clarification: I want to be able to install the package directly from Github, similar to a "poor-man's private NPM". Therefore, I don't want to publish from within the 'package' directory. I believe you can specify a branch when using Github URLs, but not a subdirectory.

Answer №1

If you want to set the NODE_PATH environment variable, follow these steps:

export NODE_PATH='yourdir'/node_modules

Check out this reference for more information.

When NODE_PATH is set to a list of absolute paths separated by colons, Node.js will look in those paths for modules if they can't be found elsewhere.

For Windows users, remember that NODE_PATH uses semicolons (;) as separators instead of colons.

NODE_PATH was originally designed to help with loading modules from different paths before the current module resolution algorithm was finalized.

Although NODE_PATH is still usable, it's not as crucial now that the Node.js community has agreed on a standard way to find dependent modules. However, deployments relying on NODE_PATH may encounter unexpected issues if NODE_PATH isn't configured correctly. Changes in a module's dependencies might result in a different version (or even a different module) being loaded during a search through NODE_PATH.

Additionally, Node.js automatically looks in certain GLOBAL_FOLDERS:

1: $HOME/.node_modules 2: $HOME/.node_libraries 3: $PREFIX/lib/node Where $HOME represents the user's home directory and $PREFIX stands for Node.js's configured node_prefix.

These folders are mainly retained for historical reasons.

It's highly recommended to keep dependencies in the local node_modules folder for faster and more reliable loading.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving the maximum number and its corresponding name from an object using JavaScript

Check out my cool react app at this link: https://i.stack.imgur.com/9VpCd.jpg I've been working on a function to find the highest and lowest latitude along with the corresponding city names. Currently, I have successfully retrieved the latitudes but ...

The margin on the right side is not functioning as expected and exceeds the boundary, even though the container is using the flex display property

I'm struggling to position the rating stars on the right side without them going outside of the block. I attempted using 'display: flex' on the parent element, but it didn't solve the issue(( Currently trying to adjust the layout of t ...

Is there a way for me to include "vendor/lib/libvips.42.dylib” within the path "node_modules/sharp/build/Release/../../“?

Is there a way to include "vendor/lib/libvips.42.dylib” in the path "node_modules/sharp/build/Release/../../“? Currently, I am working on a website using Gatsby and had to install two Gatsby plugins: npm install gatsby-plugin-offline npm install gats ...

Load information into array for jqGrid display

I am attempting to populate my JQgrid with data every time I click the "1" button, but I am encountering difficulties. As a newbie in jQuery, I am able to display the data in a p tag without any issues. Currently, I am considering whether to use push or a ...

Disabling the submit button on an MC form - step by step guide

In order to create a multiple-choice question with radio buttons, each question must have only one answer choice. Each question should provide three options for the user to select from. It is necessary to validate whether the user has answered every questi ...

How can I trigger a method after the user has finished selecting items in a v-autocomplete with multiple selection using Vuetify?

After multiple selections are made in a v-autocomplete, I need to trigger a method. However, the @input and @change events fire after each selection, not after the full batch of selections. Is there an event that triggers when the dropdown menu closes? Al ...

What is the best way to download a vast number of files with nodejs?

I have a total of 25000 image links that I need to download to my local machine using the request package in nodejs. It successfully downloads up to 14000 to 15000, but then I start encountering errors. Error { Error: socket hang up at TLSSocket.onHa ...

The behavior of Ajax is resembling that of a GET method, even though its intended method

Greetings, I am currently facing an issue while coding in Javascript and PHP without using jQuery for Ajax. My aim is to upload a file over Ajax and process it in PHP. Here is the code snippet: index.html <html> <head> <title>PHP AJAX ...

Automatic parsing and formatting of JSON object keys

My form is populated automatically using a script. Whenever the user selects an option from a dropdown, an AJAX request is triggered to an external file (which retrieves data from a database using json_encode) and populates the form fields. Here is the sn ...

Executing multiple JQuery post requests simultaneously

I am currently working with three functions, each of which posts to a specific PHP page to retrieve data. However, since each PHP script requires some processing time, there is a delay in fetching the data. function nb1() { $.post("p1.php", { ...

Incorporating the non-typescript npm package "pondjs" into Meteor applications using typescript files

Implementing the Pondjs library into my project seemed straightforward at first: meteor npm install --save pondjs However, I'm encountering difficulties when trying to integrate it with my Typescript files. The documentation suggests: In order ...

Increasing the size of a background image as you scroll

Is there a way to adjust the background image of a div so that it scales according to the amount the page is scrolled? The current implementation works fine on desktop screens, but on mobile screens, the height of the background image reduces and the image ...

Insert the ng-if directive into an element using a directive

I am working on an AngularJS directive that involves looking up col-width, hide-state, and order properties for a flexbox element based on its ID. I want to dynamically add an ng-if=false attribute to the element if its hide-state is true. Is there a way ...

Storing a JSON response in a variable

I need assistance with using the Google Geocoder API to obtain the longitude and latitude of an address for a mapping application. How can I retrieve data from a geocode request, like this example: "http://maps.googleapis.com/maps/api/geocode/json?address ...

Learn the technique of invoking a sub component's method from the parent component in Vue.js

I am looking to trigger a method in a sub component from the parent component in Vue.js in order to refresh certain parts of the sub component. Below is an example showcasing what I aim to achieve. Home.vue <template> <componentp></compo ...

Encountering issues with Docker build for React App during Gitlab CI runner execution

Struggling to set up a react app with Gitlab CI as it consistently fails at the 'RUN npm run build' step in the docker file creation process. Even tried 'RUN CI=true npm run build' without success. Below is the content of my Dockerfile ...

Managing values in Vue using v-model can sometimes lead to inconsistencies in value increment

When I try to increment or decrement the counter, my input shows a different value than what is in this.count. For example, when I increment the value, the input shows '3' but this.count === 2. Vue.component('product-item', { data: func ...

Issue with displaying content in AngularJS view set by a service

I'm currently facing a challenge in accessing the view with an expression that doesn't seem to be working correctly. Here is my Service: angular.module('myApp', []).service('myService', function($timeout){ this.sayHello = ...

Discovering the wonders of Angular: fetching and utilizing data

Recently delved into the world of Angular and I've hit a roadblock. I'm struggling to grasp how Angular accesses data in the DOM. In all the examples I've come across, data is initialized within a controller: phonecatApp.controller(' ...

Encountered an error with the post request in expess.js: TypeError - Unable to access the property 'fullName' as it is undefined

Hey everyone, I'm new to Express and having trouble posting data from Postman. The error message I'm getting is "TypeError: Cannot read property 'fullName' of undefined". Does anyone have any suggestions on how to fix this? Thank you! ...