Update NPM Packages - node.js

I seem to understand how to clone a repository, but I'm not sure I'm fully grasping how to keep that repository current with what's on Github. I'm using Basscss for example, and I believe my local project is slightly out of date with what's on Github.
I'm trying to update Basscss to the latest version using npm updatebut even after running that command my package.json file remains the same with the version stuck at "4.2.1".
"name": "basscss",
"version": "4.2.1",
...
Am I doing something wrong here? Any help with this is appreciated. Thanks in advance!

npm update will update the module's files listed in your project. if you want to update your package.json file with the newer version. use the save option.
npm update --save
edit
npm install basscss#latest --save
I would try to re-install latest and save to package file. BTW, your package.json should reference the dep's like this:
"name" : "YOUR_PROJECT",
"version" : "0.0.1",
"dependencies": {
"basscss": "^4.2.4",
}

Related

How To Update Git Hash in npm package.json git project?

How do I specify exact git hash in package.json dependencies for a Github project, and have an easy way to upgrade it at the same time?
My package.json is as follow:
{
"name": "my faboulous app",
"version": "1.0.0",
"dependencies": {
// ...
"request": "request/request#5ee89063cd"
}
}
It relies on a Github project: https://github.com/request/request and uses specific revision which is 5ee89063cd.
I want to stick to specific version, so when someones clones my project and calls npm install she has the same request dependency version as me.
But at certain point in time, there comes an important bugfix for me, and I want to upgrade the revision in package.json to the newest version that is available at Github.
Is it possible to achieve this with npm update command? How can I upgrade the revision from command line, instead of manually editing the file?
My understanding is that, when I call npm install it always takes the hash that is specified in package.json. But when I call npm update I would like to have package.json request dependency updated to the latest repository version of it with the newest revision hash.
How can I achieve that? If not with npm update maybe there is the other simple way?
Update
Checkout the git-npm-updater package which can get the job done for you.
git-npm-updater automatically updates npm dependencies presented in your package.json and create pull requests to your git repo.
Hope this helps!

Unable to install latest version of a package that is in the NPM repo

I'm having issues with a NPM and couple of dependencies where the latest version of a package that NPM finds is different from the latest version that is actually present in the NPM repo.
I'm trying to install a package that has other dependencies, but I'm unable to because I get the "No matching version found for (package)#(version)" error. However, if I go to the NPM official site, I can see that there is in fact matching version for the package I need.
I've upgraded NPM to its latest version and I have also cleaned my NPM cache.
Edit: Some of the specific packages in question - gulp-chmod#^2.0.0, sanitize-filename#^1.6.1, generator-code#1.1.22
See if the adding the following key in package.json helps you!
"engines": {
"node": "8.1.1",
"npm": "5.0.3"
}
We can specify the node and npm version in the package.json file as shown above.
In getting the same error (for a package I just updated, typeson) and looking at my log, I see it is trying to access:
https://registry.npmjs.org/typeson
While this and https://www.npmjs.com/package/typeson are showing only up to 5.17.0, http://registry.npmjs.org/-/v1/search?text=typeson is showing the currently latest version, 5.18.0.
Maybe it can just take time to propagate through the site.
Update: In my case, it still wasn't working about an hour later, so I published a new version, and it was then immediately available.

How to replace * in package.json file

I have a package.json file that lists all the dependencies I have with *'s, but I want the latest packages. I tried:
npm install --save
But that didn't replace the *'s in the file. I tried with empty strings as well, that didn't work.
Older versions of npm will update package.json when you run npm update --save, but this appears to be broken in recent versions.
Alternatively, npm-check-updates can update your package.json.
npm understands some special keywords in its package.json one of them being latest
so you can edit your file manually with something like this :
'dependencies': {
'jquery': 'latest'
}
this would always give you the latest available version of jquery no matter what.
I'd suggest you replace everything with * and run npm update --save.
This will write down the versions of the dependencies.
So
"dependencies": {
"mongo": "*"
}
will become something like
"dependencies": {
"mongo": "3.0.0"
}
EDIT: one user made a good point, * can get you in some incompatibility problems so you might want to downgrade or need to fix stuff after.

npm package from private github repo, install vs update (package.json)

I have already seen this question npm-install-vs-update-whats-the-difference
My question is around using install vs update for private github repo using git+ urls.
I have a private github repo which is used in the grunt. This repo receives frequent updates. I installed this repo using git+ssh url as mentioned here npm install git remote url
Everything works fine when installing. Problem comes when updating the package. As per my understanding and question mentioned above, npm updates the package to latest version when doing npm install but this doesnt seem to be case with package installed from github. I had to use npm update to get the latest version. I dont mind using npm update but I have observed that its slow compared to npm install. Can anyone put their thoughts why this might be happening.
My package.json looks like following
{
"name": "My Project",
"version": "1.0.0",
"dependencies": {
"grunt": "^0.4.5",
//Relevent package
"my-tasks": "git+ssh://git#github.com:Flutterbee/my-tasks.git"
}
}
PS : Using npm 3.3.3 (if that makes difference)
Can you try with specifying the branch name with in your package.json like this
"my-tasks": "git+ssh://git#github.com:Flutterbee/my-tasks.git#master"

how to Add my node_module, modules into package.json

I have some module in my node_module folder but because I am amateur in nodejs, when I wanted to install theme, I forgot to use --save with npm install.now I have lots of module but my package.json is empty so is there any way to add theme into package.json.
Sorry if my question is silly one I am beginner in nodejs
Simply change into the directory containing node_modules, backup any existing package.json in there, then use npm init to re-create the package.json.
The generated package.json will include any modules that already exist within node_modules.
Sample run:
$ cd /my/project
$ mv package.json package.json.bak # Backup package.json
$ npm init # Recreate package.json with dependencies populated
Already asked and well answered!
Here're different ways suggested to create / maintain package.json file
Is there a way to automatically build the package.json file for Node.js projects
Its simple. Edit the package.json file and add the following for development dependencies:
"devDependencies": {
"broccoli-asset-rev": "^2.0.2",
"broccoli-merge-trees": "^0.2.1",
"broccoli-svg-sprite": "^1.0.3",
......
}
To get a list of package names and version numbers, you may look at node_modules/module folder/package.json for each of the modules to pick up the official package name and version. It will be of the form:
{
"name": "<<name of the package>>",
"version": "2.1.0",
"description": "broccoli asset revisions (fingerprint)",
....
}
just copy the name and version information from above into devDependencies into your project's package.json and you should be good to go.
Also have a look here Is there a way to automatically build the package.json file for Node.js projects
and here: https://docs.npmjs.com/files/package.json
You can install the same package again using npm install --save <package> and it should just replace the current package files with freshly installed ones. It will also add the packages you already added with the default version notation.

Resources