How can I update the package.json using meteor add? - javascript

How can I get my package.json updated by meteor add command as it can be achieved by npm install --save?
I just read there that meteor writes in the .meteor/package. Does that mean package.json can only be updated via npm install --save whereas meteor add only effects .meteor/package?
I'll highly appreciate detailed information on that.

There are two ways of adding packages to a meteor project.
With meteor add
With npm install
These are two separate ways of managing packages, and one doesn't affect the other.
If you install, for example, jquery with meteor add, you'd use import {$} 'meteor/jquery' to use in a file.
If you use npm install to install jquery, then you might use import $ from 'jquery'.
Don't confuse npm packages with meteor packages.

Related

pnpm in monorepo - how to run a command only in a specific package?

Let's say I want to install a package in a specific package in my monorepo, how do I do this from root?
in npm, you can do this with something like this:
npm install react --workspace=a
I searched the docs and I can't find a way to do this in pnpm.
It is called "filtering" in pnpm docs (see it here).
In this case, you would run:
pnpm --filter=a add react
or
pnpm -F=a add react

why we use --save in react js command

I often see a key word --save parameter with react js commands. I did not understand what is this. why we use this and what is the basic purpose of this parameter.
for example
$ npm install --save react-router-dom
-–save: When this command is used with npm install this will save all your installed core packages into the dependency section in the package.json file. Core dependencies are those packages without which your application will not give desired results.
–-save-dev: With this command your installed packages will be added to devDependency section of the package.json file. Development dependencies are those packages which only meant for development purpose it will not affect the application’s result.
The --save option used to instruct npm to include the package inside of the dependencies section of your package.json.
But in the latest version of npm , --save is no longer needed.

Bumping package-lock.json and packge.lock at the same time?

Prior to publishing to NPM I need to bump the minor version. What I usually do is:
- Change package.json
- Run npm i which syncs package-lock.json with the change. Now both can be published.
Is there a way to do this with a single NPM command?
Use npm version.
For example, the following command
npm version 1.0.2
will bump both package.json and package-lock.json to 1.0.2
The following command
npm i -S <module>#<version>
installs the specific version of the given module.
-S or --save tells npm to save the reference of the module + version into both package.json and package-lock.json
It depends on the granularity of control you want to have. For example, if you just want to check for an update on an individual module you can run: npm update <pkg>. As this command will update your package.json file to save the newest version of this <pkg> as the now required version to build your project. Alternatively, you could run npm update to update all your project's top-level packages. Ok so those are the more general use cases but if you want a specific version of a package and you know the version of which you desire you can do the following: npm i --save <pkg>#<version> as this command will grab the package specified by your version number as well as update the package.json file to include this version of package as now being required to build your project. This will eliminate the need to first update the package.json file and then installing the newer version of said package, rather this will be condensed down to one step. Lastly, just for thoroughness the package-lock.json file is dynamically generated when you make important changes to your project, such as requiring new dependencies or updating existing dependencies. This file kind of serves as source of truth so others can build your project and have the same setup as you, for more information on this file take a look at the npm docs
Hopefully that helps!

What is difference between npm install and meteor npm install

I am working on Meteor and want to know that what is the difference between
npm install and meteor npm install.
Thanks
According to Meteor Development Group's comments in the official forum, the difference is as follows;
meteor npm calls the bundled npm version, so it doesn’t require npm to be installed globally, That is just a convenience however, so if you do have npm installed using that will work perfectly fine. That being said, it is a good practice to get into always using meteor npm, as that way you can make sure you’re using the same npm version that has been tested with your current version of Meteor.
When using meteor npm you can make sure that you are using the same npm version that has been tested with your current Meteor's version.
When using npm install it just uses the global npm on your machine. So i'd advise to use meteor npm
This may help you to understand difference between npm install and meteor npm install
The former is installing npm packages, which will be listed in packages.json and located in the node modules directory and need to be imported into your code.
The latter is using atmosphere packages which will be listed under .meteor/packages and will be included in your build (no need to import).

How do I run a program that I git cloned?

I'm new to git. I just git cloned this library and am trying to run the code in this folder. I know that it uses Javascript so I tried using npm start but it gave me a npm ERR! missing script: start error. How do I run it?
You should use the Getting Started guide on their docs. You are meant to install the package via npm and not cloning it using git. You would only clone the repo if you intend on modifying their code.
2.1 How to Install
This charts library is intended to be installed with npm and the built into your project with a tool like Webpack. It expects React to be present, as well as our TimeSeries abstraction library, pond.js. More on this below.
To install:
npm install react-timeseries-charts pondjs --save

Categories