NPM
npm: the ubiquitous pakage manager for Node packages
→ how we’ll get and install Express
HOW to get install npm
To get and install Express using npm, open a terminal and type npm install express. This will download the latest version of Express and install it in your project's node_modules
in the wry tradition of PHP, GNU , WINE and others, “npm” is not an acronym ; rather, it is a recursive abbreviation for npm is not an acronym.
broadly speaking, a package managers’s two primiary responsibilities are instaling packages and manging dependencies. npm is a fast, capacle, and painless package manager
which i feel is in large part responsible for the rapid growth and diversity of the Node ecosystem.
when does npm installed?
is installed when you install Node, so if you downloaded the node, you may got it
The primary command we use is npm , which means install
for example , to install Grunt (a popular Javascript task runner), you would issue the following command -
npm install -g grunt-cli
the -g flage tells npm to install the package globally
- globally
it’s available globally on the system, anywhere
this distinction will become clrearer when we cover the package.json files. For now, the rule of thumb is that Javascript utilities (like Grunt) will generally be installed globally. whereas packages that are specific to your web app o project will not
💡 unlike languages like python- which underwent a major language change from 2.0 to 3.0, necessitating a way to easily swithch between different environments. - the node platform is new enough that it is. however, if you do find yourself needing to support multiple- version of node, there is a project, nvm that allows you to switch environments |
let’s see the two ways how npm works
- local
if i don't choose other specific options, the package will be installed in local.
node_modules directory will be created in project root and the package will be installed in it.
local-installed packages can be only used in specific project
npm install <packagename>
- global
if you wanna install package in global way, you can put -g option.
it will install in global ways and it would make you to use that package on everywhere.
npm install -g <packagename>
for more, global-installed pacakage’sdownload place will be different depending on your os.
Mac: usr/local/lib/node_modules
window: c:\Users\%USERNAME%\AppData\Roaming\npm\node_modules
If you install the package in global way, it can be more comfortable to use it. but the fatal thing of this is : their info would not be written at package.json
for this, we can use -D option and install it devdependencies, and run it by npx command.
npm install -D nodemon
npm nodemon <packagename>
if you need some, there’s an analogy for you :
- Development Team Leader: Controls the work efficiency of the development team and directs work to general employees.
- Employee: A worker who is very diligent in whatever he is asked to do (?)
[ Scenario 1 ]
- The development team leader instructs each of the three employees at the same time. ( = asynchronous )
- Surprisingly, the development team leader doesn't even check what he ordered the 3 employees to do, and does his own work (= asynchronous)
- Each employee completes the assigned task on their own and reports to the development team leader. ( = non-blocking )
[ Scenario 2 ]
- The development team leader instructs employee 1 to work.
- And until the work of employee 1 is over, it gives an eye to when it is over. ( = motive )
- Employee 1's work is too slow, so he tries to give the job to another employee. ( = asynchronous )
- However, employee 1 grabs the hem of the development team leader’s clothes asking for help. ( = blocking )
- Employee 2 and Employee 3 who watch it are willing to work hard no matter what they are given, but there is no work. ( = motive )
'2023 공부한것들' 카테고리의 다른 글
[node.js] es? (es5, es6) (0) | 2023.06.18 |
---|---|
[node.js] making a simple web server with node (0) | 2023.06.18 |
[TIL] 20230618 : what's your name? (0) | 2023.06.18 |
[node.js] console.log function (0) | 2023.06.17 |
[TIL] 20230617 : killing my ocd (0) | 2023.06.17 |