Creating NPM Package for publishing best practice ENV - node.js

I'm creating a new NPM package for my TS app. It will contain centralised Interfaces, Classes, Functions etc.
Some functions in this centralised npm package have default values but can be overwritten.
Is it best practice:
to use dotenv in that centralised npm package that will be imported in other packages?
to log in that centralised npm package or return a promise to the modul that imported this npm?

Related

How to make Node.js NPM package to work with Typescript projects

I'm the owner of "memphis-dev" npm package, I want Typescript users will be able to work with this package natively.
What can I do besides refactor the entire code into TS?

How to remove optional npm packages when deploying package?

I'm making a node package written in typescript. It has a number of data providers of which the user will enable one. mssql, mongo, etc.
I'm trying to avoid having to ship all the dependencies but also not have multiple versions of my package.
I would be happy with user instructions that said ....
install my package
npm i myPackage
then install your data provider :
npm i mssql or
npm i mongo
etc
but if I exclude the dependencies I cannot compile my TypeScript because it needs the type definitions.
is there a simple solution to this? I was thinking use dev dependencies, but this doesn't really work because it assumes they all need installing unless you select -production

difference between jspm install and npm install

I'm relatively new to jspm. I wanted to know what the difference is when is run jspm install package and npm install package. I know that there is a lookup with jspm/registry. But what's the difference when it comes to setting up config.js. Are there any additional changes to be made if the package is installed using npm?
npm and jspm are both package managers.
npm is used for the node ecosystem, and traditionally served back-end dependencies.
To enforce the separation between front-end and back-end, developers used tools specifically for front-end. There came bower and the likes... as well as jspm.
I wanted to know what the difference is when is run jspm install package and npm install package.
Here are some differences between npm and jspm:
- jspm stores its dependencies in jspm_packages whereas npm stores them in node_modules
- jspm uses a flat dependency tree
- jspm allows you to configure arbitrary registries to get your dependencies from (github and npm are configured by default)
- even if jspm tracks module declaration and mapping, as well as configuration, into its own file (config.json), it actually defines the project dependencies inside the package.json (within the property jspm)
- you could use jspm packages either for a jspm project, or for a node / web project
- jspm is in fact just a package manager which wrap around the configuration system of SystemJs
So when you install a package from jspm it uses SystemJs configuration and set up the mapping between the dependencies, allowing you to export the project as any module types (AMD, CJS, esm, umd ...).
Are there any additional changes to be made if the package is installed using npm?
jspm install package makes a lookup in the jspm registry.
If no package is found, it means that you have to specify from which registry this package is coming from.
For an npm package it is: jspm install npm:package.
You can of course specify a specific version by appending #version at the end of the package name.
jspm also allows you to declare a shorthand to map this library within your code.
for more info see documentation: http://jspm.io/docs/installing-packages.html
Both are package managers and essentially do the same function however here are some differences:
Npm will track packages in the package.json file whilst jspm will use the config.json file.
Npm will store it's packages in a node_modules folder whilst jspm will use a jspm_components folder.
Jspm is more commonly used to bring in client-side\front-end libraries and npm for server-side ones.
Restoring packages will normally follow like this:
Run npm install (should install jspm amongst other libraries)
Run jspm install

What is the difference between npm 3 vs Bower?

With npm 3 coming with a flat(-ish) dependency structure, do we use Bower in future or just npm 3 when its released ?
npm is most commonly used for managing Node.js modules, but it works for the front-end too when combined with Browserify and/or $ npm dedupe.
Bower is created solely for the front-end and is optimized with that
in mind. The biggest difference is that npm does nested dependency
tree (size heavy) while Bower requires a flat dependency tree (puts
the burden of dependency resolution on the user)
merge bower into npm
npm3
npm-and-front-end-packaging
npm 3 coupled with browserify or webpack is the way to go now. Multiplying package manager in your project make your workflow harder.
Install npm 3 today with:
npm install -g npm#latest
Bower is mainly for frontend libraries, which do not have
dependencies of their own, thus in bower, flat structure is a
limitation, rather than a feature.
npm-3 is a smart dependency manager where dependencies can have their
own secondary dependencies (sub-dependencies).
It tries to create flattened structure wherever possible, but that is
not a limitation. In certain cases, it will not adhere it (for example : when you need multiple version of a dependency)

Where do the npm modules are stored?

I am learning node.js.I have few questions
Where the npm modules are stored?
2.Is it a database?
3.Is internet required for installing node modules?
npm modules are usually stored in the repository. It is a common way, but npm can install modules from an ordinary http server or git repository.
npmjs.org uses a database (CouchDB), but there are solutions that store modules in the filesystem without any database (Sinopia).
Not always, but you have to get those modules from somewhere, right?
npm modules are stored in npm registry https://npmjs.org/
If you install modules from public repository, you must have internet.
However, you can setup your private repository, see this and this

Resources