Learn TypeScript 3 by Building Web Applications
上QQ阅读APP看书,第一时间看更新

The node_modules folder content

As we saw, if you install the npm packages in a folder, they end up in the node_modules folder. If you list its contents, you'll see that each package is placed in a separate directory (let's keep it like that for simplicity, although the reality is more complex):

drwxr-xr-x 1 dsebastien 197121 0 Sep 28 19:07 . 
drwxr-xr-x 1 dsebastien 197121 0 Sep 28 19:07 ..
drwxr-xr-x 1 dsebastien 197121 0 Sep 28 19:07 .bin drwxr-xr-x 1 dsebastien 197121 0 Sep 28 19:07 accepts
drwxr-xr-x 1 dsebastien 197121 0 Sep 28 19:07 after
drwxr-xr-x 1 dsebastien 197121 0 Sep 28 19:07 anymatch
drwxr-xr-x 1 dsebastien 197121 0 Sep 28 19:07 arraybuffer.slice
...​
drwxr-xr-x 1 dsebastien 197121 0 Sep 28 19:07 karma ...​
drwxr-xr-x 1 dsebastien 197121 0 Sep 28 19:07 lodash

We have omitted the 200 plus other ones for clarity. Notice that both devDependencies and dependencies end up installed in the same base folder. This is done to avoid duplication, which is great since there are already a lot of files and folders inside node_modules. Some even go as far as calling that folder a black hole deeper than /dev/null.

Also, there is an interesting .bin folder. This is where npm places the binaries that come along with some packages such as karma:

drwxr-xr-x 1 dsebastien 197121   0 Sep 28 19:07 .
drwxr-xr-x 1 dsebastien 197121 0 Sep 28 19:07 ..
-rwxr-xr-x 1 dsebastien 197121 303 Sep 28 19:07 atob
-rw-r--r-- 1 dsebastien 197121 180 Sep 28 19:07 atob.cmd
-rwxr-xr-x 1 dsebastien 197121 301 Sep 28 19:07 karma
-rw-r--r-- 1 dsebastien 197121 178 Sep 28 19:07 karma.cmd
-rwxr-xr-x 1 dsebastien 197121 293 Sep 28 19:07 mime
-rw-r--r-- 1 dsebastien 197121 170 Sep 28 19:07 mime.cmd
-rwxr-xr-x 1 dsebastien 197121 305 Sep 28 19:07 mkdirp
-rw-r--r-- 1 dsebastien 197121 182 Sep 28 19:07 mkdirp.cmd
-rwxr-xr-x 1 dsebastien 197121 297 Sep 28 19:07 rimraf
-rw-r--r-- 1 dsebastien 197121 174 Sep 28 19:07 rimraf.cmd

We'll see how we can execute those programs next.