簡體   English   中英

npm install --save express@4.10.2是什么意思,我該如何使用它?

[英]What does npm install --save express@4.10.2 mean and how do I use it?

我是Node.JS的新手(如果能幫助您進行任何比較,我的背景是Unity C#)。

我在Socket.IO的聊天教程中

http://socket.io/get-started/chat/

我不明白這是什么意思

First let’s create a package.json manifest file that describes our project. 
I recommend you place it in a dedicated empty directory (I’ll call mine   
chat-example).

{
  "name": "socket-chat-example",
  "version": "0.0.1",
  "description": "my first socket.io app",
  "dependencies": {}
}

Now, in order to easily populate the dependencies with the things we need, we’ll 

npm install --save express@4.10.2
  1. 什么是“保存”?
  2. 這是否打算在安裝了Node.JS的服務器上的命令提示符上使用?
  1. --save表示您希望npm命令在package.json文件中寫入剛安裝的軟件包及其相應版本。 特別是在dependencies屬性中。 對於將代碼分發給托管服務和其他服務很重要。
  2. 安裝node.js后,可以打開終端並執行此命令。 在某些服務器上,package.json是自動執行的。 也就是說,將安裝依賴項,然后將運行腳本。

--save將依賴性添加到package.json文件。 例如,如果您有一個package.json,看起來像

{
  "name": "shared",
  "version": "1.0.0",
  "description": "Webapp for XYZ",
  "author": "Harsha Venkatram",
  "license": "ISC"
}

然后你做npm install --save express

該package.json將成為

{
  "name": "shared",
  "version": "1.0.0",
  "description": "Webapp for XYZ",
  "author": "Harsha Venkatram",
  "license": "ISC",
  "dependencies": {
    "express": "^4.14.0"
  }
}

之后,您可以像這樣在節點服務器JS文件中使用express框架

import express from 'express'

我們可以使用npm install express嗎,是的,我們絕對可以,並且在導入時仍然可以使用,不同之處在於,如果要將項目托管在服務器上,則必須在登錄服務器后再次執行npm install express 但是,如果您使用了--save選項,則只需執行npm install下載所有依賴項!

  1. 這是重復的問題: https : //stackoverflow.com/a/19578808/5410166

  2. 是的,它在安裝了nodejs和npm的計算機,服務器或開發計算機的終端上運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM