How to make a self-updating node package? - node.js

We have a node_module bookiza which is essentially a command line tool that people install with --global flag and then use it to create and publish books online. We are following semver for it (mostly) but I envisage it will be done so strictly in the future.
Is there a way to make this module a self-updating one? So that all our clients (writers) are on the same version of bookiza at all the times (unless they disable autoupdate). Essentially, run npm update [-g] bookiza every 15 days or when a new release is outed.
How should I go about implementing this?

For those who are looking for the same thing, I have created a module for automatically updating node.js applications from git repositories. It compares the local package.json with the one from your repo, then automatically clones the repo and install dependencies.
Auto Git Update - https://github.com/chegele/AutoGitUpdate
import AutoGitUpdate from 'auto-git-update';
const config = {
repository: 'https://github.com/chegele/BackupPurger'
tempLocation: 'C:/Users/scheg/Desktop/tmp/',
ignoreFiles: ['util/config.js'],
executeOnComplete: 'C:\\Users\\scheg\\Desktop\\worksapce\\AutoGitUpdate\\startTest.bat',
exitOnComplete: true
}
const updater = new AutoGitUpdate(config);
updater.autoUpdate();

Your users could install the command line tool a number of ways.. So it's not guaranteed that npm install -g will work, particularly in their environment.
I think the best thing to do here is make some sort of "latest version" check at start. If there's a new version, warn the user, and offer to automatically run the update command with a [Y/n].
This is what bower and a few other packages do.

Related

Cannot update the AWS-SDK package in node.js

To this make easier I created a fresh node.js application on VS code. The only package/dependency I install is AWS-SDK. in my package.json the version is shown as "aws-sdk": "^2.1314.0",
as far as I am aware the most recent version is 3.270.0. my node.js version is v14.18.1.
I have manually edited pakage.json to reflect the new version then done npm install aws-sdk again, doesnt work. sometimes it reverts back to 2.1314.0, sometimes the version I added remains but npm aws-sdk list command still shows old version
Hope this is enough information! Thanks
First of all stop using version 2 of aws sdk as it is planned to go into maintenance mode from 2023
Second from version 3, you only use you load and use only the individual AWS Services you need to save the the size of code.
if you need to use only a few AWS services, it means increasing the size of your application with code you don't need or use.
For example to use fynamodb package in version 3 you will use use
npm i #aws-sdk/client-s3
Coming to your question
delete node modules directory
npm cache clean --force
just simple remove the entry in your package.json and add entry like this
"dependencies": {
"#aws-sdk/client-s3": "^3.256.0"
}
npm i #aws-sdk/client-s3
For reference on aws sdk v3 - https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/welcome.html

Fork node_module react and install not working

I tried to fork this react native module to make some corrections, because the author abandoned the project and he was the only tool I found and meets my need, so reading an article I found out about the fork, I did this procedure, then I cloned and did necessary correction, only when having to add the module to my react project with the
yarn add lucassouza16/react-native-svg-uri
I get this error:
error Couldn't find the binary git
I'm new to this forking function, is there anything else I need to do?
My bifurcated repository:
https://github.com/lucassouza16/react-native-svg-uri
Original repository:
https://github.com/vault-development/react-native-svg-uri
To add it via npm or yarn you will need to add this firstly to npm registry. Here you have more information about it https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry
You can also add via github doing like this:
yarn add git+https://github.com/lucassouza16/react-native-svg-uri.git
You can read more about it here:
How to install an npm package from GitHub directly?
In the end all responses resulted in the same error, yet thanks to everyone who tried to help me, but it worked when I added the release version, this is the correct format:
yarn add lucassouza16/react-native-svg-uri#1.2 .4

Noflo example : Running inside browser

We are trying to get a simple noflo example running inside a browser as described the noflojs.org/documentation/fbp/ [Language for Flow-Based Programming]
We tried to refer to some examples available on GitHub
github.com/noflo/noflo-browser-app
github.com/noflo/noflo-websocket
github.com/bergie/flowcopter
We tried npm install; grunt build. We get the below error and are not able to proceed beyond this:
Running "noflo_browser:build" (noflo_browser) task install
noflo/noflo#master Warning: dns lookup failed Use --force to
continue.
Any idea what are we missing ?
At the time of the question the build setup for the projects mentioned was still based on Component.js which had become unmaintained.
Nowadays we're using NPM for installing dependencies and WebPack for browser builds.
Suggested fix would be to fetch the latest versions of these repos, do npm install and build again. This will bring the build up to spec.
If you're using the old build setup in your own projects, this PR is a handy example on what to change to go from Component.js to WebPack.

How update the node.js in plug-in HtmlToPdf to my stress situations?

my project is using the HtmlToPdf plug.it had installed in stress situation.
we have three situations on the project,stage,stress,and dev.
I check out the plug-in from svn(somehow I do not know why the svn address is the same as stage situation).
And now I updated the code in HtmlToPdf and committed to the svn.but How I update it in the stress situation to let it work on stress situation?
we use putty and marven.usually i commit code in the project and bash the sh to deployed it to the stress,but the plug-in seems like need different way.I am confused.
this is I do:
1,check out the svn code of the htmltopdf plug-in.
2,edit the code,and committed to svn.
3,open putty and logon stress root user.then,come to the path where the plug-in is installed.
4,re-installed it.for this step,i am in the path and print
npm install htmlToPdf
htmlToPdf is the file name of the the plug in svn.
and then the putty come out with a lot sentences.
the first is below:
npm WARN deprecated jade#1.11.0: Jade has been renamed to pug, please install the latest version of pug instead of jade
/
and i logon stress situaction , it has no difference.
and then i tried npm update htmlToPdf,but still no any change.
it is wrong to user npm,
npm is what i just search on internet,but i do not know what it do for.(it is really important to know why before you use it).
the correct command is svn update

How can I unflatten the node module?

My current npm version is 3.7.3 . Previously, only the required packages were getting installed in my node modules. But right now they have all flattened and have 100 + folders visible when I look into node modules. I prefer the older way where you could go into individual folders and see their dependencies.
here is a similar thread:
Why does npm install many packages into "/node_modules" instead of only one?
I tried running npm uninstall without much success.
Basically, you are out of luck... NPM does not provide any configuration options regarding this. It will nest dependencies if it must in order to resolve version conflicts, but only in this case. Your only option is to downgrade NPM (not recommended). However, if you just need to see the dependencies nested for informational reasons, you can use npm ls. It will draw you a graph.
See this relevant NPM issue for more discussion: https://github.com/npm/npm/issues/9809
Now that node js' LTS doesn't include an NPMv2 I found myself stuck with this issue again.
For those of you also caught out, the link that #KevinBurdett mentioned, also has some answers.
You can force downgrade npm using npm itself (using sudo or equivalent for this). From https://github.com/npm/npm/issues/9809#issuecomment-179702479:
as root I simply do npm install -g 'npm#<3' on my system every time I
a new version of Node comes out; your mileage might vary, but it's
fairly trivial to "downgrade" :-)
Another alternative is to use the Node Version Manager (NVM): https://github.com/creationix/nvm. Your mileage may vary depending upon personal config/preferences/platform.
That said, npm 3 and the issue of flat dependency trees will be with us from hereafter... It's probably high time to start accepting that change.
My personal grudge with this is that it makes the node_modules folder incredibly difficult to work with in an IDE, especially when you need to look at the implementation of your immediate dependent modules, without first wading through 100's of sub-sub modules that are irrelevant to me. It seems that I'm not alone in this matter when you read the comments in the issue. It only leads me to question the viability of npm itself when such changes are made without a proper migration from old to new systems. For me, npm2 will always be king.

Resources