You may have come across the scripts property in the package.json file and even write some scripts yourself. But do you know all you can do with NP...
For further actions, you may consider blocking this person and/or reporting abuse
Here is a tool to document npm scripts:
This is the most useful article I have seen on NPM scripts. Thank you for:
Wish there was a repo with useful NPM scripts.
Thanks, John! I'm glad it was helpful.
I was going to create a repo with examples to reference in this post, but in the end, it was taking me too long, and decided to just include the examples in the post. Maybe I'll keep working in the repo later 🤔
Yay! I would definitely take a look at that.
Is it common for folks to have a package.json file in their home directory for global access to NPM scripts/
This article is very concise and complete! That's rare to see around 🙏
One thing to keep in mind about parallel scripts: when you put
&
at the end of a bash command you are, actually, placing that command in background. This means that, if you use that with a server command, you'll never be able to close it with Ctrl^C!I realized that when trying to run the Firebase emulators + Svelte dev server in a single command. I can't find a clean solution to that, unfortunately 🤷🏻♂️
The best I could do is run a couple of
tmux
commands to create a single process with two outputs, but it's a bit convoluted and makes your project dependent on a platform feature (having tmux installed). I got a quick introduction to tmux in this article, and ChatGPT gave me the right commands to control the tmux session (sincetmux --help
is of no help lol).very cool, some nice new stuff that I learned :)
Thank you! Glad to hear that :)
This article is filled with so much goodness and very useful information! Thank you!
Glad to hear that 😊
Hi, I'd like to translate this awesome tutorial to Chinese. Can you give me the permission? The translated text will be published at nextfe.com
Sure! It's ok, as long as you credit me :)
Chinese translation published: nextfe.com/mastering-npm-scripts/
There is a backlink to this original post at the beginning of the translated text.
Thank you!
Super useful reference! Thanks for putting it all together ❤️
Thanks, Ruy! Happy to help :)
I thought I knew everything about NPM scripts, or most of it at least. You proved me wrong. Thanks!
Writing it had the same effect on me :P Thanks, Wojciech!
On Windows
"hello:cmd": "cd scripts && helloworld.cmd"
could be written as"hello:cmd": "scripts\\helloworld.cmd"
That didn't work for me on Windows (I tried it in CMD and PowerShell), that's why I went for the
cd
alternative. Did it work for you?Yes. But only when using double backslashes as directory separator.
I see it now, thank you! I'll update the post ASAP.
Thanks, very helpful. I was looking for how passing arguments as variable and I find this article with useful informations ! Thanks a lot ! 😃
Glad you find it helpful! :)
cool tricks. useful information regarding scripts.
Great! I'm glad you found it useful :)
Loved this article - definitely helped refresh some topics for me when I moved to a new codebase!
Thanks, Jonathan! Writing it definitely helped me refresh some stuff and learn new tricks. Happy to see it helped others as well.
I am seeing a lot of posts these days that I barely read cause it's always the same ish. But this one is a nice one. Really. Good job here
Thank you, David! I'm glad you enjoyed it.
Thanks, very helpful ☺️
Thanks, I'm glad to hear that!
Great article! I wrote a further expansion of this article on avoiding using system-specific commands in scripts: 8hob.io/posts/guides-creating-cros...
Thank you ! You made my day :)