Beginner - 1.3 npm --save command

Hello guys. I am learning the npm command and i have followed the various “react” example out there
npm i --save react react-dom

I then import it to my myapp.js with
import react from ‘react’;

Everything is good.

Now i tried it with the npm package that i want to work with particle-api-js
npm i --save particle particle-api-js

And i try to import it with my project with
import particle from ‘particle’;

When i now try to start my app i get error

W20160322-07:53:38.432(1)? (STDERR) ^
W20160322-07:53:38.433(1)? (STDERR) Error: Cannot find module './lib/main’
W20160322-07:53:38.433(1)? (STDERR) at require (C:\mobileapp\meteor\myapp.meteor\local\build\programs\server\packages\modules-runtime.js:102:19)
W20160322-07:53:38.433(1)? (STDERR) at meteorInstall.node_modules.particle.index.js (\mobileapp\meteor\myapp.meteor\local\build\programs\server\packages\modules.js:20329:18)
W20160322-07:53:38.434(1)? (STDERR) at fileEvaluate (C:\mobileapp\meteor\myapp.meteor\local\build\programs\server\packages\modules-runtime.js:193:7)
W20160322-07:53:38.434(1)? (STDERR) at require (C:\mobileapp\meteor\myapp.meteor\local\build\programs\server\packages\modules-runtime.js:99:16)
W20160322-07:53:38.434(1)? (STDERR) at meteorInstall.myapp.js (C:\mobileapp\meteor\myapp.meteor\local\build\programs\server\app\app.js:22:17)
W20160322-07:53:38.434(1)? (STDERR) at fileEvaluate (C:\mobileapp\meteor\myapp.meteor\local\build\programs\server\packages\modules-runtime.js:193:7)
W20160322-07:53:38.435(1)? (STDERR) at require (C:\mobileapp\meteor\myapp.meteor\local\build\programs\server\packages\modules-runtime.js:99:16)
W20160322-07:53:38.435(1)? (STDERR) at C:\mobileapp\meteor\myapp.meteor\local\build\programs\server\app\app.js:92:1
W20160322-07:53:38.435(1)? (STDERR) at C:\mobileapp\meteor\myapp.meteor\local\build\programs\server\boot.js:245:10
W20160322-07:53:38.436(1)? (STDERR) at Array.forEach (native)
W20160322-07:53:38.436(1)? (STDERR) at Function..each..forEach (C:\Users\emilk\AppData\Local.meteor\packages\meteor-tool\1.1.13-beta.12\\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)
W20160322-07:53:38.436(1)? (STDERR) at C:\mobileapp\meteor\myapp.meteor\local\build\programs\server\boot.js:140:5
W20160322-07:53:38.437(1)? (STDERR)

But if i import my project with this
import particle from ‘particle-api-js’;

it seems it starts fine.

My question is about this command
npm i --save particle particle-api-js

When i check my project folder i can see that under node_modules two folders are created.
particle and particle-api-js and i dont understand why that is needed, its the same for the react.

Im new to this so can someone explain why i need to do the --save as all tutorial say it should be there,
Should i not just do npm install particle-api-js.? I cant find the --save in npm documentation.

Here is my json

“name”: “myapp”,
“private”: true,
“version”: “0.0.1”,
“main”: “myapp.js”,
“scripts”: {
“start”: “meteor run”,
“test”: “meteor test-app --driver-package practicalmeteor:mocha”
“dependencies”: {
“meteor-node-stubs”: “~0.2.0”,
“particle”: “^0.1.4”,
“particle-api-js”: “^5.2.3”,
“react”: “^0.14.7”,
“react-dom”: “^0.14.7”
“keywords”: [],
“author”: “”,
“license”: “ISC”,
“description”: “”

Many thanx.

If you npm install “particle-js-api”, you should import from “particle-js-api” :slight_smile: You got the other folder because particle-js-api imports from particle, i.e., in node_modules you’ll get every single npm package needed to make your project work, i.e. direct dependencies of your project and all of their dependencies too.

As for --save, it saves the name of the dependency and it’s version to your package.json. This is useful for source control. Generally you’ll ignore and never commit your node_modules directory (since it’s all external packages). If you are cloning the project or lose this directory, if you just done npm install with a valid package.json, it will download all these packages for you again.

Thank you gadicc.

I understand what you are saying, but you say i should import from particle-api-js because thats what i install but how come then in the tutorial they import from react when they install react-dom? :slight_smile:

npm i --save react react-dom
import react from ‘react’;

should it not be import react from ‘react-dom’;
Or is there some reference im missing.

Sorry for my low level questions.


All good :slight_smile: This is new territory for us in Meteor land.

If you look carefully you’re actually npm installing TWO packages, ‘react’ and ‘react-dom’.

Most of the time you only need React, so that’s all you import. But probably in your main app entry point, you use react-dom, i.e.

import React from 'react';
import ReactDOM from 'react-dom';

const App extends React.Component {
  render() {
    return ( <div></div> );

Meteor.startup(() => {
  var div = document.createElement('div');
  ReactDOM.render(<App />, div);

Or something similar. Maybe you have it:

import { render } from 'react-dom';
  render(<App />, div);

aaa i c. how could i not see that haha.

Now i understand completely, thank you a bunch for the help.
Now i hope i can proceed a little :slight_smile:


1 Like