Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When doing require for npm package, what is meaning of slash in package name?

Tags:

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?

like image 683
codneto Avatar asked Nov 10 '15 02:11

codneto


People also ask

What does the symbol mean in npm packages?

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.

What does it mean when a package name starts with @?

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.

What is npm package name?

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.

What should be in a npm package?

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.


1 Answers

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.

like image 79
haotang Avatar answered Oct 12 '22 17:10

haotang