1

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

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 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. What is 'Save'?
  2. Is this meant to be used on a command prompt on the server with Node.JS installed?
Jim
  • 761
  • 3
  • 10
  • 32
  • Possible duplicate of [What is the --save option for npm install?](http://stackoverflow.com/questions/19578796/what-is-the-save-option-for-npm-install) – xkcd149 Jan 09 '17 at 06:46

3 Answers3

5
  1. --save means you want the npm command 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 command. On some servers, the package.json is executed automatically. That is, the dependencies will be installed, the the scripts will be run.
franckstifler
  • 396
  • 2
  • 11
4

--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 become

{
  "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 !

Harsha Venkataramu
  • 2,887
  • 1
  • 34
  • 58
2
  1. Here is the duplicate question: https://stackoverflow.com/a/19578808/5410166

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

Community
  • 1
  • 1