How do I time my npm install? - node.js

I am trying to see how much time npm install takes to complete installing all my dependencies. Is there a way for me to time this process, natively (in npm) or using some third party plugin? I've tried
* npm i --verbose
* npm i --silly
* slow-deps (A third party lib that analyzes your npm packages)
slow-deps gave me a decent result, but I am not sure about it's accuracy, as it doesn't run as part of the npm install process.
Is there any other way to accurately time-profile the npm install process? I'm looking for an output like this (output screenshot from Yarn):

Thanks for your help. I have come across a few utilities for this:
The time utility mentioned by #JJJ in the comments section.
Paypal's gnomon package, that updates timestamps to everything.

Use time linux command and have the following command:
time npm install
Also according to https://www.commandlinux.com/man-page/man1/time.1.html
Users of the bash shell need to use an explicit path in order to run the external time command and not the shell builtin variant.
so your command may be (I am a macOS user and I am using the below command):
/usr/bin/time npm install
The output of this command (at the last line) would be something like this:
153.96 real 67.63 user 34.12 sys
so basically what you are looking at is the real number that are in seconds. To the above example the time taken is:
153.96s

Related

Play a sound or notify when npm install is done

I was thinking , would it be helpful and efficient to get a notification(sound or popup) back after npm finish running a task , a long installation for example . I'm using vscode and running most of my command in the integrated terminal and while waiting for it to finish I ended up spending more time on doing other task that is non-productive.
So we can break this down to running npm install, followed by some way of making a sound. According to this thread, a simple beep can be done using:
echo -en "\007".
Combine these two, and you get:
npm install; echo -en "\007"
The use of ; ensures that the beep is played even if npm install fails (as opposed to && which only runs the beep if the first command is successful). You could also look here for how to start playing a song with VLC: play-only-audio-with-vlc
If your npm install is part of a task, VSCode 1.72 (Sept. 2022) will offer:
add audio cue for task end and terminal bell
Fixes "Play sound upon completion of build so that users can multi-task (do work in other applications) and know when the build has completed "
Settings audioCues.taskEnded
This has been released to VSCode Insiders yesterday.
for cmd like Terminals
Your_Command && [System.Media.SystemSounds]::Beep.Play()
Sounds:
Beep, Hand, Quetsion, Asterisk, Exclamation
You can also play the raw sound and changes its pitch and duration
[console]::beep(1000,500)
For a slightly different solution there is a npm package named benny-hill:
Play the Benny Hill theme while running another command
e.g.
npx benny-hill npm install
will play Yakety Sax while you're waiting.
Actually there is a npm package doing exactly what you are asking for:
Literally tells you when a command is done running.
E.g.
npx okimdone npm install
It depends on external speech to text tools like espeak or festival to produce the audio.

how to run mbpipe... a program I just installed

I'm trying to use this tool: https://github.com/mapbox/node-mbtiles/wiki/Post-processing-MBTiles-with-MBPipe
I've installed mbtiles with npm install -g mbtiles. I've also installed it locally (in the dir I'm working in) with just plain npm install mbtiles.
That part worked (I was able to download the files), but now according to the readme I can just start entering in commands like
mbpipe 'pngquant 64' myMbTilesFile.mbtiles and it's supposed to work?
Umm... don't I have to run a specific script file (like "node scriptfile.js")? This is acting like I can call functions within a script and pass it variables? I can tell you, as the user mentioned, that 'mbpipe' is within the utils.js file I have.... but how am I supposed to use it?
when I enter in the above command, I of course get "mbpipe: command not found"
So... what are they talking about?

Jenkins build step fails when calling "npm" on mac-os-x Yosemite

Before I start, I want to say that I already checked these answers:
Jenkins build step fails on 'npm install <whatever>'
Jenkin's build failing on npm install
Now, I'm dealing with this issue for a while already and thus I tried a bunch of stuff.
Firstly, I installed node + npm via homebrew. A simple $ node -v and $ npm -v echoed the version v0.10.36 for node and v2.3.* for npm, which also means I HAVE THEM IN THE PATH and they work while called in the terminal.
Simply adding node -v; npm -v to the execute shell in Jenkins didn't do it. After a bit of tinkering I copied what $: which node yielded in the terminal to the above mentioned script, which now looked like this: /usr/local/bin/node and apparently that worked. The Jenkins build succeeded and 'node-v0.10.36' was proudly displayed in the console output.
When doing the same for 'npm' which happened to be /usr/local/bin/npm --version the computing gods weren't so merciful anymore. A big 'env: node: No such file or directory' error was thrown this time and the whole build failed.
The actual command that fails is
$ /bin/sh -xe /var/folders/wr/g_dl81tn5_x0t_yz3jw602cr0000gn/T/hudson8770480548136671253.sh and "surprisingly" when I run the same command in the terminal it succeeds.
I also uninstalled the homebrew node & npm versions and installed them afterwards via the package manager. Same results.
Ultimately I also did this: https://gist.github.com/DanHerbert/9520689, with no luck.
Notes:
I'm running Jenkins 1.613 and tried with 1.5**
I didn't create a "Jenkins" specific user but instead I'm using the admin. This happens to be the same user that Jenkins runs, since the who am i command inside the executable script yields the admin's user name.
sudo'ing doens't help
I'm also running the whole thing in a Virtual Environment - vagrant
I'm not running Jenkins as a deamon, as it's conflicting with xtools, but as a simple process
I also tried out jenkins-node plugin with various configs (can detail if needed)
Thanks a lot for your help, and let me know if you need any other info, screenshots, logs, etc.
I found my own solution. The problem was that the PATH although visible in shell was not exported for the Jenkins job, and so, the first workaround, as found here, was to export it in the actual script like so:
but this feels like a hack!
The right and elegant solution is to use Jenkins EnvInject Plugin and export the path in the added Properties content textarea on the configuration page, like so:
Manage Jenkins -> Configure System -> Global properties -> Environment variables

Changing --max-stack-size for grunt task

I'm running into the following error in my GruntJS script:
Maximum call stack size exceeded"
What's the proper syntax for invoking the node flag --max-stack-size= in my grunt command so I can set aside a larger amount of memory for the stack?
Unless you are doing some very high-level programming in GruntJS I think you may have a cyclic task registered.
If you name a task the same name as plugin it will run an infinite amount of times:
grunt.registerTask('uglify', ['uglify'])
This results in the task calling itself.
In order to verify what you're doing, run the grunt with --verbose (or --v) command to see what grunt is running.
For instance run grunt uglify --v and notice how many times it runs. This can be fixed easily by changing the task name to something else.
If however you're sure of what you're doing run grunt with --max-stack-size=10000
or whatever...
Install grunt-cli locally with npm install grunt-cli then call it locally with:
node --max-stack-size=val ./node_modules/.bin/grunt
Although likely you're getting that error because of an infinite recursion that should be fixed.
This should work on linux or mac:
node --stack-size=10000 `which grunt`
The 10000 can be replaced by whatever size you require.
The default is 984 on my mac and on an ubuntu server I've been working on lately.
Another option is to add this to your .bashrc, .bach_profile or equivalent:
alias grunt='node --stack-size=10000 `which grunt`'
Similar issue happend to me when I dynamicaly called tasks via grunt.task.run().
Seems that grunt's success callbacks filled tha NodeJs stack.
I performed manual edit of c:\Users\%UserName%\AppData\Roaming\npm\grunt.cmd (on Windows). Add parameter supported by your version of node, e.g --stack_size=2000 (for details use node -help).

Node.js Cygwin not supported

I am trying to install node.js. I followed this tutorial and i am stuck in the middle.
When I write ./configure in my cygwin terminal it says "cygwin not supported". Please help me out
Thanks in advance.
Node in my experience runs fine in cygwin, what Node usually has EINVAL errors in seems to be MINTTY which is a terminal emulation 'skin' that is default to cygwin. I still am not sure why these EINVAL errors happen 100% but the following are the steps and tricks I use to get node working.
In my /cygwin/home/{username}/.bashrc I add node to path so cygwin can find it
export PATH=$PATH:"/cygdrive/c/Program Files/nodejs/"
If you run a 32 bit version of node:
export PATH=$PATH:"/cygdrive/c/Program Files (x86)/nodejs/"
Then to make npm run without windows to linux issues I launch cygwin in admin mode then run:
dos2unix '/cygdrive/c/Program Files/nodejs/npm'
At this point running files and most npm packages will run in MINTTY just fine, although every once and awhile you will run into EINVAL issues with certain npm packages as karma. Also you will not be able to run the interpreter directly in MINTTY, anytime I want to do these things I run:
cygstart /bin/bash
This will open a native cygwin bash.exe window, from here you run the interpreter or an any troubling package command that results in a EINVAL. It slightly sucks you have to do this but I rarely use this day to day, and I love MINTTY too much to not use it.
Also note that you can run any one line node code in MINTTY by just running something like:
node -e "console.log('hello node')"
As a simpler derivative of troy's answer for those just looking to install NPM packages:
Install Node.js with the Windows installer package.
Add it to the PATH with export PATH=$PATH:"/cygdrive/c/Program Files/nodejs/" (obviously replacing the path to Node.js's installation directory with where you installed it).
There's a current bug in the Windows version that can be fixed by running mkdir -p ~/AppData/Roaming/npm. This is a bug for all of Windows and not just Cygwin. At some point of the future, you won't have to do this anymore, but the command shouldn't have any negative side effects.
Test it. Eg, npm install pretty-diff -g.
In order to be able to run the newly installed software, you'll need to add the install locations to your PATH. You can find these with npm bin -g and npm bin (the -g flag is the "global" installation location).
Not really anything special that you have to do to get it to run in Cygwin (although I can't say if everything works).
Use Console2, it allows you to run create tabs of CLI shells. It seems running cygwin inside console2 allows me to use node REPL just fine. I have no idea why :P
Follow this guide to add cygwin to console2:
http://blog.msbbc.co.uk/2009/11/configuring-console-2-and-bash-with.html
With Bjørn's suggestion (using Console2) and Soyuka's alias (steps here), my node.js v0.10.13 and npm v1.3.2 are now working under Babun v1.02, a Cygwin distribution.
For windows, Just run bash.exe in cmd, so that you could have a bash work around with cmd console directly, which could support ALL NODE WORKING PERFECTLY.
C:\Users\郷>bash
郷#CHIGIX ~
$ node
>
I'm using this wrapper in /usr/local/bin/node (note no extension!)
#!/bin/sh
_cmd="$(cygpath -lw -- "$1" )"
shift
"/proc/cygdrive/C/Program Files/nodejs/node.exe" "$_cmd" "$#"
This is far from perfect, as Node do not understand Cygwin directory tree, but works relatively well with relative names.
From Windows, run Cygwin.bat (instead of Cygwin Terminal) then in that run node: see and reply on this answer on this effectively-same question asked 1.5 years later.
Grab and run the node.js Windows installer.
In the Cygwin prompt type node
See if it works.

Resources