Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
To develop and test your own npm package locally, use npm link.
Example: a package named flaviocopes-common-database. Create a package.json with the module name and its dependencies:
{
"name": "flaviocopes-common-database",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"pg": "^8.0.2",
"sequelize": "^5.21.6"
}
}
From the package directory, run:
npm link
This creates a symbolic link in the global npm modules folder (e.g. /usr/local/lib/node_modules/) pointing to your local package directory.
Then, in another project where you want to use this package, run:
npm link flaviocopes-common-database
You can now import it in your Node.js code with require():
const database = require('flaviocopes-common-database')