I have some npm packages that are used internally in company projects, and I would like to expose some of the interfaces used by dependencies from this component.
So if I have a project for a npm package (called company-utils) that has a dependency with axios, and I want to expose a method that creates an instance for axios, how can I export it so other projects that installs this company-utils can see the axios interfaces/methods/etc ?
It seems to me that you are using this company-utils as a wrapper for axios? If you want to export something you can put an index.js at the root of the package and export it there. Then it will be exposed to anyone who installs the package.
so the structure will be:
package
src/
index.js
package.json
Then inside index.js
import method from 'src/<path to method file>'
export method
If you install the package into another project that method will be exposed
import method from 'package'
Related
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?
I create my project "data" and I want to use it as a library in an another project. For this, I did the following steps:
cd project
yarn add ../../packages/data (the path of my project) It adds a new dependency in package.json like this "#info/data": "../../packages/data"
to install this dependency I run yarn install
but it doesn't appear in node_modules and I don't know why
Any help please
For that you will have to create an npm module, there is a step by step availabe on the official documents here: creating-node-js-modules
And, apart from creating the directory where your code will be placed and the exports for each method, you will also have to publish your module: npm-publish
You can use npm to publish your library to all npm users or to yourself
To do this, enter npm login in the terminal of the code editor and
log in, before that, register on npm
If you haven't initialized the project then do it npm init
After you publish the library to the npm server, npm publish, remember the name of the library will take the name of the folder
https://www.youtube.com/watch?v=Ufwbp838yZA Example
perhaps yarn also has such a function
I installed a public github repo using the syntax provided in the repository's readme:
npm install https://github.com/user_name/proj_name.git
However, I'm not sure how to load this module into my js code. I've tried:
const my_lib = 'proj_name';
Unfortunately, this is not working for me. How can I load a module that was installed directly from a github repository?
Currently you're just defining a constant as a string with value 'proj_name'.
To load a module from node_modules, you have to do the following:
npm install <package_name> --save, where --save write the package and version in your dependencies of package.json. You can also use --savedev to write the package in your devDependencies (both optional).
Use const packageName = require('packageName'); in your e.g. app.js to use the package in your code.
See here for more details about npm install in general, specifying-dependencies and here for ecma script require and import.
I install bootstrap with
npm install bootstrap --save
in my express project, then bootstrap is installed in node_modules, but how can I access the js and css in my jade file?
Node_modules is meant to use for server modules. NPM is server package management system.
You should use client package management system like bower for your client side modules i.e. Bootstrap.
Once you set up bower, you'll be able to reference bower_components in your html files.
It depends on how you configure your static server, e.g.:
app.use(express.static('public'));
So if node_modules is placed into public folder, your jade file will be:
script(src='/node_modules/bootstrap/js/file.js')
But better approach is use bower_component instead of node_modules on the client-side
UPDATE:
I'm using atmosphere npm package to work with node modules
I'm using this package to connect with github-api
https://github.com/mikedeboer/node-github
This package doesn't have method to get statistics of a user
There is a one pull request, In which he implemented that method
https://github.com/mikedeboer/node-github/pull/131
I made those changes in /packages/npm/.npm/package/github and restarted the server and error showing that
object has no method getStatsContributors
You can see the code I've added in that pull request
What I'm doing wrong?
you should add npm package to your meteor app
mrt add npm
And after that look at that : Meteor.require