how to Include a npm package in my npm package - node.js

i am create a npm package and i want date-npm package for my npm package how to include this package to my npm package,any way?

If you’re just building an npm library then just include date lib in your package.json dependencies. Once a user installs your lib, then npm will take care of the rest.

Just execute
npm install date-npm
in your package.
Once your package is published, anyone installing your package, like:
npm install your-groovy-package-here
will have date-npm, as well as any other dependencies your package might have, installed along with it.

Related

How to install all relevant packages?

I have a Node.js project which has several dependencies.
I created the package.json file (npm init)
and try to install all the relevant packages
(npm install all) or (npm install)
with npm install I'm getting the following result:
npm notice created a lockfile as package-lock.json. You should commit this file.
but
when I'm trying to run, I'm getting error that a package is missing (i.e express and I need to install it manually)
Is there a way (command) to install at once (with one command) all the relevant packages and dependencies ? (instead of install each of the package manually) ?
Update 1:
I think I found the solution to your problem, you can use this npm module for auto installing your dependencies.
Install
npm install -g auto-install
Usage
Run auto-install in the directory you are working in.
So npm is simple!
you can add a single package using npm install package-name
or
you can install all using npm install, this will read your package.json file and install all the packages which are in there
Additionally you can do this:
npm install package1 package2 package to install multiple packages.
If a required dependency is not installed, just install it once manually using npm's --save argument and it will automatically add that dependency to your package.json.
For instance, if you are missing the express dependency, just run:
npm install --save express
That will install the dependency in your node_modules folder and also automatically update your package.json file to include express. On subsequent installs on different machines, you'll now only need to run npm install and the express package will be added automatically.
Update with a little more context: In Node your package.json file defines all dependencies that are required for your project. However, these dependencies are not automatically generated for you. npm init will create a boilerplate package.json, but it will not fill that package.json with any dependencies.
You need to define the dependencies yourself, which you can do one of two ways:
Manually add lines to your package.json's dependencies section
Use npm install --save <package name> to have npm install a package and automatically save that package as a dependency in your package.json file
If you aren't familiar with package.json files, I'd recommend sticking to approach number 2 so that npm handles editing that file for you.
Once you have a package.json with all of the dependencies you need, then when you pull down your project onto new machines you will be able to automatically install all dependencies at once using a simple npm install command. You can test this on your own machine by deleting the node_modules folder and running npm install, then trying to run your project. If it runs fine then you successfully added all dependencies to your package.json. If it complains about a missing package then add that package with npm install --save <package>

npm install --save not installing the module

I am integrating firebase cloud functions with my app's workflow. I needed to install a package so I did npm install --save #sendgrid/mail. The installation was a success but I can't see the dependency either in node_modules folder or the package.json file. What do I do?
One way to add the package would be to do the reverse. Add #sendgrid/mail to your package.json with the version you want, and then run npm install.

Using --ignore-scripts for one dependency in NPM

Following this question, NPM dependencies can be installed using:
$ npm install --ignore-scripts
Is there a way to mark that a dependency should be installed without running scripts in package.json?
This is because, when I run npm install --ignore-scripts, the dependency is added to package.json. As a result, other users will install the package while running scripts, however I want this certain package to never run scripts.
I could be wrong but I believe its: npm install -ignore-script package-name#version

NPM: Never install nested optional dependencies for npm package

I'm authoring a package A which I want to publish to NPM.
A has a dependency on package B, which in turn has a dependency on package C. C then has two optional native dependencies D and E. I know for definite I have no use for the optional dependencies, D and E, and NEVER want to try and install them when someone installs my package.
I know you can use the command npm install A --no-optional -g to install the package without optional dependencies, but this would be knowledge/overhead that I'd rather consumers of the package not need.
Is there any npm config or workaround where consumers of package A can just npm install A or npm install -g A and optional dependencies will never be installed?
Thanks
npm install A --no-optional
Test to see if everything works.
npm list
Make sure you have no errors.
npm shrinkwrap
That will lock down the dependencies for the packages.
That way npm install will look into npm-shrinkwrap.json before trying to install dependencies.
You can read more about it here https://docs.npmjs.com/cli/shrinkwrap

"npm install" independent of npmjs.org

npm install downloads packages from npmjs.org, compiles and then installs. So even if the node_modules folder is taken backup it can not be used on other machines where the os might be different, due to the native machine code generated during the npm install.
Also another problem with npm install is that it downloads from npmjs.org. What if the site goes down?. How to download the packages and the same package be installed offline on all platforms?
You can tell npm to use a mirror if npmjs.org is down. For example:
npm set registry http://registry.npmjs.eu/
Or with a runtime option:
npm --registry http://registry.npmjs.eu/ install express
If you do keep the node_modules directory with your code, you can simply run npm rebuild to re-compile anything that needs it.
Otherwise, you have a lot of options for installing from various locations. You could keep package tarballs locally. From the documentation:
npm install (with no args in a package dir)
npm install <tarball file>
npm install <tarball url>
npm install <folder>
npm install [#<scope>/]<name> [--save|--save-dev|--save-optional] [--save-exact]
npm install [#<scope>/]<name>#<tag>
npm install [#<scope>/]<name>#<version>
npm install [#<scope>/]<name>#<version range>
npm i (with any of the previous argument usage)

Resources