admin管理员组

文章数量:1394735

I'm incredibly new to Node.JS (My background is Unity C# if that helps you with any parisons).

I'm on the chat tutorial for Socket.IO

/

I don't understand what this means

First let’s create a package.json manifest file that describes our project. 
I remend 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 [email protected]
  1. What is 'Save'?
  2. Is this meant to be used on a mand prompt on the server with Node.JS installed?

I'm incredibly new to Node.JS (My background is Unity C# if that helps you with any parisons).

I'm on the chat tutorial for Socket.IO

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

I don't understand what this means

First let’s create a package.json manifest file that describes our project. 
I remend 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 [email protected]
  1. What is 'Save'?
  2. Is this meant to be used on a mand prompt on the server with Node.JS installed?
Share Improve this question asked Jan 8, 2017 at 19:47 JimJim 8013 gold badges13 silver badges34 bronze badges 1
  • Possible duplicate of What is the --save option for npm install? – xkcd149 Commented Jan 9, 2017 at 6:46
Add a ment  | 

3 Answers 3

Reset to default 5
  1. --save means you want the npm mand to write in your package.json file the package(s) he just installed with their corresponding versions. Specifically in the dependencies property. It is important for distributing your code to a hosting service and others.
  2. When you have installed node.js, you have the possibility of opening a terminal and executing this mand. On some servers, the package.json is executed automatically. That is, the dependencies will be installed, the the scripts will be run.

--save will add the dependency to the package.json file. For example, if you have a package.json that looks like

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

and you do npm install --save express

the package.json would bee

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

After which you can use the express framework in your node server JS file like so

import express from 'express'

Can we use npm install express , yes we definitely could and it would still work when you import, the difference being, if you want to host your project on a server, you would have to again do an npm install express after logging onto your server. However, if you had used the --save option, just an npm install would download all the dependencies !

  1. Here is the duplicate question: https://stackoverflow./a/19578808/5410166

  2. Yes, it is run on the terminal of the puter with nodejs and npm installed, a server or your dev puter.

本文标签: javascriptWhat does npm install save express4102 mean and how do I use itStack Overflow