{"id":1098,"date":"2025-03-12T21:21:30","date_gmt":"2025-03-12T21:21:30","guid":{"rendered":"https:\/\/razvanvancea.ro\/blog\/?p=1098"},"modified":"2025-03-12T22:06:06","modified_gmt":"2025-03-12T22:06:06","slug":"how-to-repeat-any-cli-command-for-x-times-using-npm-repeat-cli-command","status":"publish","type":"post","link":"https:\/\/razvanvancea.ro\/blog\/2025\/03\/12\/how-to-repeat-any-cli-command-for-x-times-using-npm-repeat-cli-command\/","title":{"rendered":"How to repeat any CLI Command for X times using NPM repeat-cli-command"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div>\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1098\" class=\"elementor elementor-1098\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-38e860a elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"38e860a\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-4052d63\" data-id=\"4052d63\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-aa2256f elementor-widget elementor-widget-text-editor\" data-id=\"aa2256f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In this article I will show you an awesome NPM tool that I created called <a href=\"https:\/\/www.npmjs.com\/package\/repeat-cli-command\" target=\"_blank\" rel=\"noopener\"><strong>repeat-cli-command<\/strong><\/a>.<strong>\u00a0<\/strong>It is open source and I invite you to contribute to it. This tool allows you to repeat any CLI command effortlessly for an X number of times.\u00a0<\/p><p>Whether you are running tests, debugging, or just want to loop a command, this tool has you covered.<\/p><p>Let&#8217;s dive in!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3f78d0d elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3f78d0d\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-127141a\" data-id=\"127141a\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-af1df11 elementor-widget elementor-widget-heading\" data-id=\"af1df11\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Installation<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f95ad39 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f95ad39\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b1a1c5a\" data-id=\"b1a1c5a\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-310385e elementor-widget elementor-widget-text-editor\" data-id=\"310385e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>First, install it globally (-g) or at project level (-D) with npm.<br \/><br \/><strong>npm install -g repeat-cli-command<\/strong><\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-ae23dd2 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ae23dd2\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-7ad483b\" data-id=\"7ad483b\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3ee732e elementor-widget elementor-widget-heading\" data-id=\"3ee732e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Usage<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-b4765ce elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"b4765ce\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3b6370e\" data-id=\"3b6370e\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9d3c794 elementor-widget elementor-widget-text-editor\" data-id=\"9d3c794\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>Let's say we want to repeat a simple command like printing \"Hello\" to the terminal, for 5 times. We just run<\/pre><p>\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4cd73df elementor-widget elementor-widget-text-editor\" data-id=\"4cd73df\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre><strong>npx repeat-cli-command \"echo 'Hello' \" --times=5<\/strong><\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6ef2c48 elementor-widget elementor-widget-text-editor\" data-id=\"6ef2c48\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Now, let&#8217;s say you&#8217;re working with PactumJS for API testing (or any other testing framework) and want to rerun the tests for 10 times.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cfb7f3c elementor-widget elementor-widget-text-editor\" data-id=\"cfb7f3c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre><strong>npx repeat-cli-command 'npx mocha api_tests --timeout=10000' --times=10<\/strong><\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-352d0b8 elementor-widget elementor-widget-text-editor\" data-id=\"352d0b8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>What if you have some web e2e automated tests with TestCafe? No problem!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8fec97a elementor-widget elementor-widget-text-editor\" data-id=\"8fec97a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre><strong>npx repeat-cli-command 'npx testcafe chrome:headless web_tests' --times=2<\/strong><\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-490c573 elementor-widget elementor-widget-text-editor\" data-id=\"490c573\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Simple, isn&#8217;t it?<\/p><p>This is how you can use repeat-cli-command to boost productivity! It works with any CLI command and can become handy for testing, debugging, and much more.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ecad10f elementor-widget elementor-widget-spacer\" data-id=\"ecad10f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"spacer.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-spacer\">\n\t\t\t<div class=\"elementor-spacer-inner\"><\/div>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cbaa528 elementor-widget elementor-widget-text-editor\" data-id=\"cbaa528\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Enjoyed this article? Make sure to subscribe to my\u00a0<em><a href=\"https:\/\/www.youtube.com\/@LearnwithRV\" target=\"_blank\" rel=\"noopener\">YouTube Channel<\/a><\/em>\u00a0for more Test Automation tutorials, and follow me on\u00a0<a href=\"https:\/\/www.linkedin.com\/in\/razvanvancea\/\" target=\"_blank\" rel=\"noopener\"><em>LinkedIn<\/em><\/a>\u00a0and\u00a0<em><a href=\"https:\/\/twitter.com\/razvanvancea\" target=\"_blank\" rel=\"noopener\">Twitter<\/a><\/em>\u00a0for regular insights.<span style=\"font-weight: bold;\"><br \/>Looking to improve your test automation skills?<br \/><\/span>I&#8217;ve created a<span style=\"font-weight: bold;\">\u00a0personalized 1-on-1 Mentoring program\u00a0<\/span>refined to<span style=\"font-weight: bold;\">\u00a0boost YOUR CURRENT skills.\u00a0<\/span>Reach out at\u00a0<a rel=\"noopener\">iamrv@razvanvancea.ro<\/a>\u00a0for more details and\u00a0<span style=\"font-weight: bold;\">together\u00a0<\/span>will create a<span style=\"font-weight: bold;\">\u00a0learning path\u00a0<\/span>adapted to\u00a0<span style=\"font-weight: bold;\">your skills and goals\u00a0<\/span>that you are aiming for<span style=\"font-weight: bold;\">,<\/span>\u00a0in a<span style=\"font-weight: bold;\">\u00a0timely-efficient manner\ud83d\ude80<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-9b675bb elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"9b675bb\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-e5b8914\" data-id=\"e5b8914\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-6bf972b elementor-widget elementor-widget-video\" data-id=\"6bf972b\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;youtube_url&quot;:&quot;https:\\\/\\\/www.youtube.com\\\/watch?v=efD08BFvILk&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}\" data-widget_type=\"video.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-wrapper elementor-open-inline\">\n\t\t\t<div class=\"elementor-video\"><\/div>\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>In this article I will show you an awesome NPM tool that I created called&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1100,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13,12],"tags":[],"class_list":["post-1098","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-tools"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/razvanvancea.ro\/blog\/wp-content\/uploads\/2025\/03\/Copy-of-MacOS-Tools-to-BOOST-Productivity-1.png","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/posts\/1098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/comments?post=1098"}],"version-history":[{"count":10,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/posts\/1098\/revisions"}],"predecessor-version":[{"id":1109,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/posts\/1098\/revisions\/1109"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/media\/1100"}],"wp:attachment":[{"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/media?parent=1098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/categories?post=1098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/razvanvancea.ro\/blog\/wp-json\/wp\/v2\/tags?post=1098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}