No more require("./../../../../../../../../some/other/file.js").
In large node.js applications, relative require()
can be really annoying. You probably already know code like this:
var moduleA = require("./../../../../../../../../path/to/moduleA.js");
var moduleB = require("./../../../../../../../../path/to/moduleB.js");
var moduleC = require("./../../../../../../../../path/to/moduleC.js");
This module allows you to write code like this:
var moduleA = require("your-app/path/to/moduleA.js");
var moduleB = require("your-app/path/to/moduleB.js");
var moduleC = require("your-app/path/to/moduleC.js");
link-package just creates a symlink in your project's node_modules
pointing to your project folder (or a sub-folder).
You can use link-package in two ways:
- npm scripts
- node API
Add this to the scripts
-section of your package.json
:
"scripts": {
...
"prestart": "link-package",
"pretest": "link-package",
...
}
This will create the symlink before you run npm start
or npm test
.
Subfolders: If you want the symlink to point to a subfolder like app
or lib
you can also pass an argument to link-package
:
"prestart": "link-package app",
"pretest": "link-package app",
If you don't want to use npm scripts you can also use the node API like this:
var linkPackage = require("link-package");
linkPackage();
// or if you want to link a subfolder
linkPackage("app");
You don't need to check if there is already a symlink, link-package does that for you.
Against popular beliefs, symlinks are well supported on Windows.
Unlicense