Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of @ symbol in Node module names [duplicate]

People also ask

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 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.

Does copying node modules work?

You can always copy node_modules and then run npm install or npm update in the new project to make sure you've got up-to-date versions. npm will use the files in node_modules as a cache and should only bring down newer content if required. In short: it won't hurt.


Scoped packages in npm are preceded by an '@' symbol.

Scopes are a way of grouping related packages together, and also affect a few things about the way npm treats the package. Each npm user/organization has their own scope, and only you can add packages in your scope. This means you don’t have to worry about someone taking your package name ahead of you. Thus it is also a good way to signal official packages for organizations. https://docs.npmjs.com/misc/scope

A scope allows you to create a package with the same name as a package created by another user or Org without conflict. https://docs.npmjs.com/about-scopes

The docs include additional information on requiring scoped packages: https://docs.npmjs.com/misc/scope#requiring-scoped-packages

Requiring scoped packages

Because scoped packages are installed into a scope folder, you have to include the name of the scope when requiring them in your code, e.g.

require('@myorg/mypackage')

There is nothing special about the way Node treats scope folders, this is just specifying to require the module mypackage in the folder called @myorg.


The @ scope is indicates common package ownership for a set of packages

From the official documentation is at: https://docs.npmjs.com/about-scopes

When you sign up for an npm user account or create an Org, you are granted a scope that matches your user or Org name. You can use this scope as a namespace for related packages.

A scope allows you to create a package with the same name as a package created by another user or Org without conflict.

The main advantage of scopes I've seen so far is that each scope is controlled by npm account of an organization / user, much like GitHub usernames / organization names.

This way, it makes it easy to determine if the package you are looking at belongs to an organization you trust, or if it is a third party tool.

For example, if you see a package:

@angular/cli

then you know that it comes from the user / group that controls the Angular team and can be trusted.

On the other hand, the same could not be said about:

angular-cli

TODO: the web UI / URL scheme is really wonky, how do you easily link: https://www.npmjs.com/package/@angular/cli to the corresponding organization / user page, presumably https://www.npmjs.com/~angular ? By searching the page source, the only hit for that URL is under "collaborators", but that contains other collaborators as well: https://www.npmjs.com/~angular-cli and https://www.npmjs.com/~google-wombot

See also: What is the meaning of the "at" (@) prefix on npm packages?


So I solved this one myself.

Turns out @company/config is one of our private NPM repositories, hosted on npm and defined by this alias to an internal GitHub repository: it had nothing to do with how require works.

Using @ may or may not be a protocol that I was unaware of for private NPM repos, keep that in mind if you run into this.


Apart from scoped packages, the '@' can arise due to module-alias package in npm. Through module aliasing you can use frequently used modules without requiring its entire path. Also its effective when directory structure is long. e.g.) require('../../../../some/very/deep/module')

Instead you can use: var module = require('@deep/module')

In package.json you can provide the modules for which you are providing alias:

"_moduleAliases": {
  "@root"      : ".", // Application's root
  "@deep"      : "src/some/very/deep/directory/or/file",
  "@my_module" : "lib/some-file.js",
  "something"  : "src/foo", // Or without @. Actually, it could be any string
}

And in the main file of the app use this:

require('module-alias/register');

Refer here for detailed info: module-alias