Skip to content

Commit 236497f

Browse files
committed
docs on npm
1 parent e734f51 commit 236497f

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
* [Prettier](docs/tools/prettier.md)
7979
* [Husky](docs/tools/husky.md)
8080
* [Changelog](docs/tools/changelog.md)
81+
* [NPM](docs/npm/index.md)
8182
* [TIPs](docs/tips/main.md)
8283
* [String Based Enums](docs/tips/stringEnums.md)
8384
* [Nominal Typing](docs/tips/nominalTyping.md)

docs/npm/index.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# NPM
2+
3+
> Fun fact `npm` is [not an acronym](https://twitter.com/npmjs/status/347057301401763840) so it doesn't expand to anything, but among friends it is commonly called `node package manager`.
4+
5+
`npm` is a binary that comes with default `node` installations used to manage community shared JavaScript / TypeScript packages.
6+
7+
8+
* NPM packages are hosted at (and installed from) https://www.npmjs.com/
9+
10+
## Quick common setup
11+
12+
* npm packages are configured using `package.json` file. You can generate a quick file using `npm init -y`.
13+
* packages get installed into a `./node_modules` folder. You normally have this folder in your `.gitignore`.
14+
15+
Even though you might be building an application, having a `package.json` essentially makes your project a package as well. So the terms your `project | package` can be used interchangably.
16+
17+
## Installing a package
18+
You can run `npm install <something>`. Most people will use the shorthand `npm i <something>` e.g.
19+
20+
```ts
21+
// Install react
22+
npm i react
23+
```
24+
25+
> This will also automatically add `react` into your `package.json`'s `dependencies`.
26+
27+
## Installing a devDependency
28+
`devDependencies` are dependencies that are only required during *development* if your project and not required after deployment.
29+
30+
`typescript` is common in `devDependencies` as its only required to build `.ts -> .js`. You normally deploy the built `.js` files:
31+
32+
* into production
33+
* OR for consumption by other other npm packages
34+
35+
## Security
36+
The public `npm` packages are scanned by security team worldwide and issues get reported to npm team. They then release security advisories detailing the issue and potential fixes. Commonly the fix is simply updating the package.
37+
38+
You can run an audit on your node project by simply running `npm audit`. This will highlight any vulnerabilities that might exist in the package / dependencies of the package. e.g.
39+
40+
```
41+
┌───────────────┬──────────────────────────────────────────────────────────────┐
42+
│ Low │ Regular Expression Denial of Service │
43+
├───────────────┼──────────────────────────────────────────────────────────────┤
44+
│ Package │ debug │
45+
├───────────────┼──────────────────────────────────────────────────────────────┤
46+
│ Dependency of │ jest [dev] │
47+
├───────────────┼──────────────────────────────────────────────────────────────┤
48+
│ Path │ jest > jest-cli > istanbul-lib-source-maps > debug │
49+
├───────────────┼──────────────────────────────────────────────────────────────┤
50+
│ More info │ https://nodesecurity.io/advisories/534 │
51+
└───────────────┴──────────────────────────────────────────────────────────────┘
52+
```
53+
54+
Note that commonly the issues are found in *development* dependencies (e.g. jest in this case). Since these aren't are a part of your production deployments, most likely your production application is not vulnerable. But still good practice to keep vulnerabilities to `0`.
55+
56+
## Public vs. Private packages
57+
You don't need this when *using* any of the common public npm packages. Just know its there for enterprise / commercial customers.
58+
59+
### Public packages
60+
* Packages are public by default.
61+
* Anyone can deploy a package to npm.
62+
* You just need an account (which you can get for free).
63+
64+
No one needs an account to download a public package.
65+
66+
This free sharing of packages is one of the key reasons of success for npm 🌹.
67+
68+
### Private packages
69+
70+
If you want a private package for your company / team / enterprise you need to sign up to a paid plan, details here : https://www.npmjs.com/pricing
71+
72+
Of-course you need an account with the right permissions to download a private package.
73+

0 commit comments

Comments
 (0)