While "requiring" non-local NodeJS modules, what is the meaning of slash in module name?
Example:
from ShellJS npm module's github page (link: https://github.com/shelljs/shelljs#javascript)
require('shelljs/global');
require('shelljs/make');
Upon looking at the directory structure of ShellJS github project, I notice that both global.js and make.js are both at same level as shell.js which is the main entry point of the module as per its package.json. So what does the slash mean in the package name and how, in above example, is the path to "global" and "make" resolved?
Major, minor and patch represent the different releases of a package. npm uses the tilde (~) and caret (^) to designate which patch and minor versions to use respectively. So if you see ~1.0. 2 it means to install version 1.0. 2 or the latest patch version such as 1.0.
It allows organizations to make it clear which packages are 'official' and which ones are not. For example, if a package has the scope @angular , you know it was published by the Angular core team.
All npm packages have a name. Some package names also have a scope. A scope follows the usual rules for package names (URL-safe characters, no leading dots or underscores). When used in package names, scopes are preceded by an @ symbol and followed by a slash, e.g.
A minimal npm package should contain metadata in a package. json file and an associated source file (usually index. js). In practice, packages contain more than that and you will have at least a license file and the source in various formats.
Slash (as it primary use), is just simply used for file paths.
require('shelljs/global')
will load script of global.js
file.
require('shelljs/make')
will load script of make.js
file.
However, require('shelljs')
will load script of shell.js
. Why? Let's look at the content of package.json
: It's "main": "./shell.js"
that makes the magic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With