I am pretty familiar with composer and now looking into npm, the command below doesn't seen to change the package.json file like composer require slim/slim 2.4.3
npm install express
Is changing the json manually necessary?
you should add the --save option :
npm install express --save
Related
Following this tutorial, I have installed express-session using this code:
npm install express-session --save --save-exact
But now when I try to run the code, node is telling me I need a package called "buffer-crc32"
I see this listed as a require() in the drive where I install express-session, but I'm confused because the index.js file stored on my computer seems different from the one shown on github here.
What gives? Why isn't that dependency installing when I run "npm install" or "npm update"? Thanks.
I figured it out. I had to stop using '--save-exact' in my npm install command and update the version in my package.json document
I'm building new React App to learn and play with Draft-js, RichStyle Text Editor.
I used create-react-app to initialize my React application. It's working, and very easy to use.
Now, I tried to add semantic-ui-react, which is React version of SemanticUI lib.
Aaaaannd fail.
npm install semantic-ui-react --save
As you can see, same effect for draft-js.
My issue is that normally there's no problem to use draft-js & semantic-ui-react with React 15.4.2. I use this stack in professional env.
Is there something I'm missing with npm ? Is create-react-app can stop this install ?
Now, I can't install any packages. This error shows up everytime. But, I cant still npm start for my local web server. I also tried npm cache clean
Is my very simple package.json
Thanks again for you help.
Solution : Just update NPM and everything working.
Edit : My App folder :
And my npm & node version
My guess is that you have old npm or node versions, you can't start the project with this versions... you can upgrade npm and node programs.
if you are using brew on OSX then you can use following commands to upgrade them.
brew update
brew upgrade node
npm install -g npm
I'm inside a folder
c:\nodeProject\node_modules\express>
Now, i want to update the module here, to the latest version.
I want NPM to check the package.json, and update this module.
What is the command line to do it?
npm uninstall express
npm install express#latest --save
That's what your looking for ?
I have created the package.json using npm init. After some stage I installed few more modules as per the need.Rather than updating the package.json dependencies manually, is there any way to automatically update it??
If I understand what you are asking correctly, you want to use npm to install a dependency and have that dependency automatically added to your package.json ?
If so, use --save after the package name :
npm install [package name] --save
For download the all packages configured in the package.json, use:
npm update --save
Docs: https://docs.npmjs.com/cli/update
I understand the differences between npm install something and npm install something --save (for anyone wondering, the first one will install the dependency only while the latter will install the dependency and add it to your package.json).
However I do not understand why there is a --save option in the first place. In other words, why would you ever want to install a dependency without adding it to your package.json file? Why is the --save option not default?
A lot of websites/npm modules/SaaS suggest installing their module using npm install something (newrelic is one of them for instance), am I missing something?
Edit: Starting from NPM 5, --save is now on by default.
You would have a scenario such as you need some module to install without adding dependency to package.json file, for ex. you just want to try some module, and not sure you would be really using that module in production or while deploying, so instead adding the module dependency to package.json, just give it a try without using --save. this is why npm install without --save exists.
But For most of your modules you might require using --save, for ex. npm install express --save,
in this case you surely know that you are going to use express for you application.
The other scenario, for not using --save, would be, npm install heapdump or npm install nodemon, I would use it for testing my apps performance, but not add a dependency in the package.json :)
Also, As #surajck said in comment below: when you are doing global installs, in that case adding dependencies using --save, to the package.json would not make sense.
I just learned a nice trick from Jonathan Mills' JavaScript Best Practices course on Pluralsight. From the terminal:
npm config set save=true
Now I don't need to remember --save anymore. And I also now use
npm config set save-exact=true
Because I want the exact version of the package not the ^ prefix.
By default with version npm 5.0+ npm install adds the module to the dependencies list in the package.json file; with earlier versions of npm, you must specify the --save option explicitly. Then, afterwards, running npm install in the app directory will automatically install modules in the dependencies list.