1 ---
2 title: About packages and modules
3 redirect_from:
4 - /getting-started/packages
5 ---
6
7 The npm registry contains packages, many of which are also Node modules, or contain Node modules. Read on to understand how they differ and how they interact.
8
9 ## About packages
10
11 A **package** is a file or directory that is described by a `package.json` file. A package must contain a `package.json` file in order to be published to the npm registry. For more information on creating a `package.json` file, see "[Creating a package.json file][pkg-json]".
12
13 Packages can be unscoped or scoped to a user or organization, and scoped packages can be private or public. For more information, see
14
15 - "[About scopes][about-scopes]"
16 - "[About private packages][private-pkgs]"
17 - "[Package scope, access level, and visibility][pkg-viz]"
18
19 ### About package formats
20
21 A package is any of the following:
22
23 - a) A folder containing a program described by a `package.json` file.
24 - b) A gzipped tarball containing (a).
25 - c) A URL that resolves to (b).
26 - d) A `<name>@<version>` that is published on the registry with (c).
27 - e) A `<name>@<tag>` that points to (d).
28 - f) A `<name>` that has a `latest` tag satisfying (e).
29 - g) A `git` url that, when cloned, results in (a).
30
31 ### npm package git URL formats
32
33 Git URLs used for npm packages can be formatted in the following ways:
34
35 - `git://github.com/user/project.git#commit-ish`
36 - `git+ssh://user@hostname:project.git#commit-ish`
37 - `git+http://user@hostname/project/blah.git#commit-ish`
38 - `git+https://user@hostname/project/blah.git#commit-ish`
39
40 The `commit-ish` can be any tag, sha, or branch that can be supplied as an argument to `git checkout`. The default `commit-ish` is `HEAD`.
41
42 Installing any package directly from git will not install [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) or workspaces.
43
44 ## About modules
45
46 A **module** is any file or directory in the `node_modules` directory that can be loaded by the Node.js `require()` or `import` syntax.
47
48 To be loaded by the Node.js `require()` function, a module must be one of the following:
49
50 - A folder with a `package.json` file containing a `"main"` field.
51 - A JavaScript file.
52
53 To use the `import` syntax, a module should also include `"type": "module"` in its `package.json` file:
54
55 ```json
56 {
57 "name": "my-package",
58 "type": "module"
59 }
60 ```
61
62 <Note>
63
64 **Note:** Since modules are not required to have a `package.json` file, not all modules are packages. Only modules that have a `package.json` file are also packages.
65
66 </Note>
67
68 In the context of a Node program, the `module` is also the thing that was loaded _from_ a file. For example, in the following program:
69
70 ```
71 const req = require('request')
72 ```
73
74 The `req` variable refers to the `request` module returned by the `require()` function.
75
76 [about-scopes]: about-scopes
77 [private-pkgs]: about-private-packages
78 [pkg-json]: creating-a-package-json-file
79 [pkg-viz]: package-scope-access-level-and-visibility