I'm building custom nodes for a Node-RED app (http://nodered.org/) and published each one as a private NPM module and put them in my package.json like this:
"#di-dash/node-red-contrib-didash-output": "0.0.1",
but that makes them install inside of a parent directory like this:
/node_modules/#di-dash/node-red-contrib-didash-output
The fact that they're in a parent directory now instead of directly in the node_modules directory like they were when I was just pulling in github repos as depencencies prevents Node-RED from noticing them and including them in the app.
I wrote a grunt script to pull them out of the parent directory and put them directly into node_modules and put it as a "postinstall" script in package.json but that must happen after the app inits because the Node-RED app isn't picking up my custom nodes anymore.
Any ideas how to make the private modules install without a parent directory so that they're just like normal (non-private) NPM modules?
Like this:
node_modules/node-red-contrib-didash-output
Instead of:
/node_modules/#di-dash/node-red-contrib-didash-output
It's not that they are private modules, it's that they are scoped modules. They are supposed to be in a directory with the same name as the scope they are under. The only way to make them install in root is by removing the scope from the packages. I suggest seeking support from the Node-RED team to see if they have a workaround for scoped modules.
Edit: I took the liberty of opening an issue for you :)
https://github.com/node-red/node-red/issues/885
Related
I want to try and make some changes to a package published in npm? (I've suggest some changes as an issue but I think they are simple enough for me to attempt them).
https://www.npmjs.com/package/bt-presence#contributing--modifying
The author supplies some information on how to modify the package, but not really enough for someone doing it for the first time.
Where should I clone the GitHub repo to? The folder where the package is installed? I tried it in my home folder and that would not build (unmodified).
The command npm run build - where is this run from? The root folder of the package where the package.json is?
Will I need to modify the package.json?
In general what is the best way to develop something like this for npm? I've worked on packages before but they were simply Javascript.
If you want to work on the bt-presence package in isolation, you can put the cloned repository anywhere. If you want to use your modified version of bt-presence in combination with an application, my recommended approach is to register bt-presence as a dependency in the application's package.json file with the version set to a relative path to your bt-presence repository; then running npm install in the application will make a symlink from node_modules/bt-presence in the application to your bt-presence repository.
npm run build should indeed be run from the root folder that contains the package.json of bt-presence.
If you just want to change the code of bt-presence, you won't need to modify its package.json. You would only modify the package.json if you need to change any of the settings in there, e.g, if you need to add additional dependencies to your version of bt-presence.
None of the above is really specific to TypeScript. (Some JavaScript packages have build processes too if they need to transform or package the JavaScript files in some way.)
I'm developing microservice architecture on nodejs.
I moved 'core' functionality to separate git repository, and each 'service' add that core as npm dependency.
In service I use core as
require('core/module1');
In that case nodejs takes 'core' from node_modules, it's ok for production but for development I want to take 'core' from the external folder not from node_modules.
My main idea - do changes in 'core' and immidiately get the result in 'service'.
I cannot use NODE_PATH for specify external 'core' folder, because I've used it now.
I found solution to use 'app-module-path' module for adding additional directories to the Node.js module search path.
if(isDevelopment()){
require('app-module-path').addPath('path_to_core_folder');
}
It's working solution, but maybe you can suggest some more clear way?
My folders structure
- core
module1
- service1
-index.js
-node_modules
-core
Thanks.
Either one works. If you require('modulename') and it's present in your node_modules folder, it will be loaded from there. If you want it to load from another folder or from your main folder, you need to do require('./modulename") which will look for it in the current folder. Alternatively you can do require('./my_modules/modulename') which will work for a subfolder.
i would look at the mockrequire module, it allows you to redirect the directory your modules are loaded from
npm link is the answer to your problem. You can run the below command in the root directory of 'service1' (where your package.json is present)
npm link [../relative-path-to/library]
Refer to https://docs.npmjs.com/cli/v7/commands/npm-link for more details about npm link.
I'm trying to create a npm package of a couple React components. These will be used in a couple of other projects so I would like them in a separate package.
What I would like to be able to do is require('comps/a-component') from an app using this package. I could do this by putting all my components in the root of the module, but I don't want to do that. Instead I want to have all components in src/components/ because the root will be overcrowded.
This seems like a trivial thing to do but I have not yet succeeded. I've looked through https://docs.npmjs.com/files/package.json trying to find an option to set the root or something. Does anyone have any ideas on how to achieve this?
Thanks!
You can make symlink in you node_modules directory to your components directory. This would allow you to require your components from anywhere in your app like you said: require('comps/a-component'). To create the symlink on a linux or osx you can do something like this
cd ./node_modules; ln -snf ../src/components comps;
Another option would be to actually create npm packages out of each component, that way you could have them listed in your dependencies of your package.json.
Another promising option that was released in npm 2.0 are local dependencies. This allows you to point to a local npm package on your file system. In this case each component would have to be written as an npm package with a package.json https://docs.npmjs.com/files/package.json#local-paths
If your app is like this:
- AppFolder
|-index.js
|-Readme.md
|-/src
|-app.js
|-anotherThing.js
If I want to use anotherThing.js, I can just do var anotherThing = require('./src/anotherThing');. Unless I fail to understand your problem.
Or maybe you meant the main attribute in package.json
Does anyone know how to configure location of global repository?
My global repo is somewhere under $HOMEDRIVE/$HOMEPATH/blahblahblah
and all my packages are being installed under that place fopr global reference
but I want to park it somewhere specific and secret like the docroot of my appserver ? so I can operate demos and proof-of-concepts and prototypes ands show them off
can you tell me how I can configure the path to my global repository? I am on windows7 which is thoroughly supported and chmod chown issues are not as prevalent on linux
is this directory anchor controlled by a designated variable within NPM?
is this variable ever referenced by javascript modules indiscriminantly? i would hope not
I assume this variable is within the NPM tool itself.
what about bower... would bower operate the same configurable? or is bower a different animal and place.
is bower a subset of npm? anmd of so does it operate the same configuration as npm?
thank you
See the npm docs about the folders. It states that the global modules are installed under a configured prefix. You can get it from the npm config comand:
npm config get prefix
And you may change it with a similar command:
npm config set prefix /path/to/my/global/folder
However, modules are usually installed globally if want to use some command line command they provide. For using in some node.js application, prefer to install them locally. If you still want to use the globally installed modules inside the application, you should use the link command (though I'm not sure if it works in a Windows environment).
Bower is another thing completely. Looking at the api documentation, you will see that there is no option to install modules globally (which makes sense, as Bower is intended for front-end dependencies).
You could change the default folder using the directory parameter of your .bowerrc file (see the documentation). This way you would be able to set all projects to use the same folder, but notice that's not the way it's intended to use and you would need to set it in all projects.
npm config set registry <registry url>
once this command is run, check in ~/.npmrc, it must show your changes.
I'm in the process of developing a Meteor package, that has a dependency on a node module. This module is also, under development, so right now it's just a local folder.
Looking around, it seems that adding
Npm.depends({ "npmmodulename": "x.x.x"});
on the package.js file, it should be enough, but how do I do this, when the npm module is local? I tried adding the path to the module, instead of the version, but I had no luck...
Can this be actually done?
You don't need to specify an Npm.depends clause because your node package is not yet published to npmjs.org so it doesn't matter.
Let's assume your node package is in "my-project/packages/my-package/node-package".
You can reference it from your meteor package like this :
my-project/packages/my-package/server.js :
var nodePackage=Npm.require("../../../../../packages/my-package/node-package");
All the ../.. stuff is needed because the current working directory of a meteor node process is "my-project/.meteor/local/build/programs/server".
Note that using this technique, meteor doesn't take care of building your node package, so you need to manually "npm install" it each time you modify it's inner dependencies.