Is there a way to get the version from the ‘package.json’ file in Node.js code?

I found that the following code fragment worked best for me. Since it uses require to load the package.json, it works regardless of the current working directory. var pjson = require(‘./package.json’); console.log(pjson.version); A warning, courtesy of @Pathogen: Doing this with Browserify has security implications. Be careful not to expose your package.json to the client, as … Read more

What is the (ERR! code ENOLOCAL npm ERR!) Could not install because of an error?

This is an issue in node which is caused by white space in your windows username (possibly between the first-name and last-name in windows). run the following command after replacing firstname with your windows user firstname in command prompt with administrator access npm config set cache “C:\Users\Firstname~1\AppData\Roaming\npm-cache” –global

How to automatically copy files from package to local directory via postinstall npm script?

Since npm 3.4 you can use the $INIT_CWD envar: https://blog.npmjs.org/post/164504728630/v540-2017-08-22 When running lifecycle scripts, INIT_CWD will now contain the original working directory that npm was executed from. To fix you issue add to your postinstall script in package.json the following: “scripts”: { “postinstall”: “cp fileYouWantToCopy $INIT_CWD”, },

What does npm mean by ‘Skipping failed optional dependency’?

This is not an error. It is a warning that fseventsd, which is Mac OS specific, cannot be installed on Linux. There is no need to be alarmed, and the package that needs fsevents will still work – that’s why it’s an optional dependency. Since many people are confused about this (particularly since this used … Read more

npm ERR! Unable to authenticate, need: Basic realm=”Artifactory Realm”

Artifactory moved to support APIKEY only. If your old _auth was base64 encoding of username:password or username:encrypted_password then both are unacceptable now. You must use APIKEY in place of these. So, the supported _auth now becomes: _auth: APIKEY But ironically, even this didn’t work in some cases. Following seemed to be more reliable: You need … Read more

tech