Modern Full-Stack Development



Download 5,64 Mb.
Pdf ko'rish
bet14/107
Sana06.08.2021
Hajmi5,64 Mb.
#140576
1   ...   10   11   12   13   14   15   16   17   ...   107
Bog'liq
Modern Full-Stack Development Using TypeScript, React, Node

 Adding  Dependencies
Now, let’s say you want to add that Express package I mentioned to this project. There 
are two choices. First, you could edit package.json yourself, adding this element:
"dependencies": {
  "express": "^4.16.1"
}
However, doing just that won’t have any effect. The module isn’t installed at this 
point. To do that, you now must issue a command:
npm install
NPM will now (using Node as a runtime, it should be mentioned, because NPM is 
just a JavaScript application that runs on Node) go fetch the Express package from the 
central repository, will determine all the dependencies it needs, and will download 
and install all of them in the node_modules directory under the current directory. All 
these modules are now in the project cache (not global cache, it should be noted) and 
ready for you to use (normally, you wouldn’t use the transient dependencies of Express 
directly, though you certainly could, but it’s good form to declare all the modules you 
intend to use explicitly in package.json as dependencies).
Another alternative, and the one generally favored by developers, is not to edit the 
file directly and instead let NPM do it by issuing a command like this:
npm install express --save
Chapter 1   Server-Side aCtion: node and npM


14
This will cause NPM to add the dependency entry in package.json for you. This 
avoids the possibility of accidentally fat-fingering something and having a broken 
experience (or, worse, handing the project to another developer only to get the dreaded 
“It won’t even start up!” call).
Note  You can also replace --save with --save-dev. this results in a 
devDependencies entry being added to package.json. the difference is 
that devDependencies are modules that you only need during development, 
but which your project code itself doesn’t depend on. as you’ll see later, two 
good examples of this are typeScript and Webpack. also, when uninstalling 
dependencies, --save and --save-dev can also be used to remove the 
dependency from package.json.
The reason this is all important is that, now, let’s say you want to give this project 
to someone else. You typically do not want to provide them with all the dependencies 
your project requires, all the content of node_modules, if for no other reason that that 
directory can quickly grow to a large size. Instead, they can recreate it using the  
package.json file just by doing this:
npm install
That will cause NPM to read the package.json file and automatically install all 
the dependencies! Now, the person you’re working with has the same development 
environment as you as far as project dependencies go for this project without having to 
do any leg work themselves! Pretty sweet, right?
As you can guess, there’s quite a bit more to NPM than just what I’ve shown here, but 
these are the real basics.

Download 5,64 Mb.

Do'stlaringiz bilan baham:
1   ...   10   11   12   13   14   15   16   17   ...   107




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish