concurrently. 6.3.0 • Public • Published a month ago. Readme · Explore BETA · 8 Dependencies · 1,046 ...
concurrently6.3.0 • Public • PublishedamonthagoReadmeExploreBETA8Dependencies1,046Dependents40Versions
Concurrently
Runmultiplecommandsconcurrently.
Likenpmrunwatch-js&npmrunwatch-lessbutbetter.
Tableofcontents
Concurrently
Why
Install
Usage
ProgrammaticUsage
concurrently(commands[,options])
FAQ
Why
Iliketaskautomationwithnpm
buttheusualwaytorunmultiplecommandsconcurrentlyis
npmrunwatch-js&npmrunwatch-css.That'sfinebutit'shardtokeep
ontrackofdifferentoutputs.Alsoifoneprocessfails,othersstillkeeprunning
andyouwon'tevennoticethedifference.
Anotheroptionwouldbetojustrunallcommandsinseparateterminals.Igot
tiredofopeningterminalsandmadeconcurrently.
Features:
Crossplatform(includingWindows)
Outputiseasytofollowwithprefixes
With--kill-othersswitch,allcommandsarekilledifonedies
Spawnscommandswithspawn-command
Install
ThetooliswritteninNode.js,butyoucanuseittorunanycommands.
npminstall-gconcurrently
orifyouareusingitfromnpmscripts:
npminstallconcurrently--save
Usage
Remembertosurroundseparatecommandswithquotes:
concurrently"command1arg""command2arg"
Otherwiseconcurrentlywouldtrytorun4separatecommands:
command1,arg,command2,arg.
Inpackage.json,escapequotes:
"start":"concurrently\"command1arg\"\"command2arg\""
NPMruncommandscanbeshortened:
concurrently"npm:watch-js""npm:watch-css""npm:watch-node"
#Equivalentto:
concurrently-nwatch-js,watch-css,watch-node"npmrunwatch-js""npmrunwatch-css""npmrunwatch-node"
NPMshortenedcommandsalsosupportwildcards.Giventhefollowingscriptsin
package.json:
{
//...
"scripts":{
//...
"watch-js":"...",
"watch-css":"...",
"watch-node":"...",
//...
},
//...
}
concurrently"npm:watch-*"
#Equivalentto:
concurrently-njs,css,node"npmrunwatch-js""npmrunwatch-css""npmrunwatch-node"
#Anynameprovidedforthewildcardcommandwillbeusedasaprefixtothewildcard
#partofthescriptname:
concurrently-nw:npm:watch-*
#Equivalentto:
concurrently-nw:js,w:css,w:node"npmrunwatch-js""npmrunwatch-css""npmrunwatch-node"
Goodfrontendone-linerexamplehere.
Help:
concurrently[options]
General
-m,--max-processesHowmanyprocessesshouldrunatonce.
Newprocessesonlyspawnafterallrestarttriesofa
process.[number]
-n,--namesListofcustomnamestobeusedinprefixtemplate.
Examplenames:"main,browser,server"[string]
--name-separatorThecharactertospliton.Exampleusage:
concurrently-n"styles|scripts|server"--name-separator
"|"[default:","]
-r,--rawOutputonlyrawoutputofprocesses,disablesprettifying
andconcurrentlycoloring.[boolean]
-s,--successReturnexitcodeofzerooronebasedonthesuccessor
failureofthe"first"childtoterminate,the"last
child",orsucceedonlyif"all"childprocessessucceed.
[choices:"first","last","all"][default:"all"]
--no-colorDisablescolorsfromlogging[boolean]
Prefixstyling
-p,--prefixPrefixusedinloggingforeachprocess.
Possiblevalues:index,pid,time,command,name,
none,oratemplate.Exampletemplate:"{time}-{pid}"
[string][default:indexorname(when--namesisset)]
-c,--prefix-colorsComma-separatedlistofchalkcolorstouseon
prefixes.Iftherearemorecommandsthancolors,the
lastcolorwillberepeated.
-Availablemodifiers:reset,bold,dim,italic,
underline,inverse,hidden,strikethrough
-Availablecolors:black,red,green,yellow,blue,
magenta,cyan,white,gray,oranyhexvaluesfor
colors,eg#23de43
-Availablebackgroundcolors:bgBlack,bgRed,
bgGreen,bgYellow,bgBlue,bgMagenta,bgCyan,bgWhite
Seehttps://www.npmjs.com/package/chalkformore
information.[string][default:"reset"]
-l,--prefix-lengthLimithowmanycharactersofthecommandisdisplayed
inprefix.Theoptioncanbeusedtoshortenthe
prefixwhenitissetto"command"
[number][default:10]
-t,--timestamp-formatSpecifythetimestampinmoment/date-fnsformat.
[string][default:"yyyy-MM-ddHH:mm:ss.SSS"]
Inputhandling
-i,--handle-inputWhetherinputshouldbeforwardedtothechild
processes.Seeexamplesformoreinformation.[boolean]
--default-input-targetIdentifierforchildprocesstowhichinputonstdin
shouldbesentifnotspecifiedatstartofinput.
Canbeeithertheindexorthenameoftheprocess.
[default:0]
Killingotherprocesses
-k,--kill-otherskillotherprocessesifoneexitsordies[boolean]
--kill-others-on-failkillotherprocessesifoneexitswithnonzerostatus
code[boolean]
Restarting
--restart-triesHowmanytimesaprocessthatdiedshouldrestart.
Negativenumberswillmaketheprocessrestartforever.
[number][default:0]
--restart-afterDelaytimetorespawntheprocess,inmilliseconds.
[number][default:0]
Options:
-h,--helpShowhelp[boolean]
-v,-V,--versionShowversionnumber[boolean]
Examples:
-Outputnothingmorethanstdout+stderrofchildprocesses
$concurrently--raw"npmrunwatch-less""npmrunwatch-js"
-Normaloutputbutwithoutcolorse.g.whenloggingtofile
$concurrently--no-color"gruntwatch""http-server">log
-Customprefix
$concurrently--prefix"{time}-{pid}""npmrunwatch""http-server"
-Customnamesandcoloredprefixes
$concurrently--names"HTTP,WATCH"-c"bgBlue.bold,bgMagenta.bold"
"http-server""npmrunwatch"
-Sendinputtodefault
$concurrently--handle-input"nodemon""npmrunwatch-js"
rs#Sendsrscommandtonodemonprocess
-Sendinputtospecificchildidentifiedbyindex
$concurrently--handle-input"npmrunwatch-js"nodemon
1:rs
-Sendinputtospecificchildidentifiedbyname
$concurrently--handle-input-njs,srv"npmrunwatch-js"nodemon
srv:rs
-ShortenedNPMruncommands
$concurrentlynpm:watch-nodenpm:watch-jsnpm:watch-css
-ShortenedNPMruncommandwithwildcard
$concurrentlynpm:watch-*
Formoredetails,visithttps://github.com/open-cli-tools/concurrently
ProgrammaticUsage
concurrentlycanbeusedprogrammaticallybyusingtheAPIdocumentedbelow:
concurrently(commands[,options])
commands:anarrayofeitherstrings(containingthecommandstorun)orobjects
withtheshape{command,name,prefixColor,env,cwd}.
options(optional):anobjectcontaininganyofthebelow:
cwd:theworkingdirectorytobeusedbyallcommands.Canbeoverridenpercommand.
Default:process.cwd().
defaultInputTarget:thedefaultinputtargetwhenreadingfrominputStream.
Default:0.
handleInput:whentrue,readsinputfromprocess.stdin.
inputStream:aReadablestream
toreadtheinputfrom.Shouldonlybeusedintherareinstanceyouwouldliketostreamanythingotherthanprocess.stdin.OverrideshandleInput.
pauseInputStreamOnFinish:bydefault,pausestheinputstream(process.stdinwhenhandleInputisenabled,orinputStreamifprovided)whenalloftheprocesseshavefinished.Ifyouneedtoreadfromtheinputstreamafterconcurrentlyhasfinished,setthistofalse.(#252).
killOthers:anarrayofexittingconditionsthatwillcauseaprocesstokillothers.
Cancontainanyofsuccessorfailure.
maxProcesses:howmanyprocessesshouldrunatonce.
outputStream:aWritablestream
towritelogsto.Default:process.stdout.
prefix:theprefixtypetousewhenloggingprocessesoutput.
Possiblevalues:index,pid,time,command,name,none,oratemplate(eg[{time}process:{pid}]).
Default:thenameoftheprocess,oritsindexifnonameisset.
prefixColors:alistofcolorsassupportedbychalk.
Ifconcurrentlywouldrunmorecommandsthantherearecolors,thelastcolorisrepeated.
Prefixcolorsspecifiedper-commandtakeprecedenceoverthislist.
prefixLength:howmanycharacterstoshowwhenprefixingwithcommand.Default:10
raw:whetherrawmodeshouldbeused,meaningstrictlyprocessoutputwill
belogged,withoutanyprefixes,colouringorextrastuff.
successCondition:theconditiontoconsidertherunwassuccessful.
Iffirst,onlythefirstprocesstoexitwillmakeupthesuccessoftherun;iflast,thelastprocessthatexitswilldeterminewhethertherunsucceeds.
Anythingelsemeansallprocessesshouldexitsuccessfully.
restartTries:howmanyattemptstorestartaprocessthatdieswillbemade.Default:0.
restartDelay:howmanymillisecondstowaitbetweenprocessrestarts.Default:0.
timestampFormat:adate-fnsformat
tousewhenprefixingwithtime.Default:yyyy-MM-ddHH:mm:ss.ZZZ
Returns:aPromisethatresolvesiftherunwassuccessful(accordingtosuccessConditionoption),
orrejects,containinganarrayofobjectswithinformationforeachcommandthathasbeenrun,intheorder
thatthecommandsterminated.Theobjectshavetheshape{command,index,exitCode,killed},wherecommandistheobject
passedinthecommandsarray,indexitsindexthereandkilledindicatesiftheprocesswaskilledasaresultof
killOthers.Defaultvalues(emptystringsorobjects)arereturnedforthefieldsthatwerenotspecified.
Example:
constconcurrently=require('concurrently');
concurrently([
'npm:watch-*',
{command:'nodemon',name:'server'},
{command:'deploy',name:'deploy',env:{PUBLIC_KEY:'...'}},
{command:'watch',name:'watch',cwd:path.resolve(__dirname,'scripts/watchers')}
],{
prefix:'name',
killOthers:['failure','success'],
restartTries:3,
cwd:path.resolve(__dirname,'scripts'),
}).then(success,failure);
FAQ
Processexitedwithcodenull?
FromNodechild_processdocumentation,exitevent:
Thiseventisemittedafterthechildprocessends.Iftheprocess
terminatednormally,codeisthefinalexitcodeoftheprocess,
otherwisenull.Iftheprocessterminatedduetoreceiptofasignal,
signalisthestringnameofthesignal,otherwisenull.
Sonullmeanstheprocessdidn'tterminatenormally.Thiswillmakeconcurrent
toreturnnon-zeroexitcodetoo.
Doesthisworkwiththenpm-replacementsyarnorpnpm?
Yes!Inallexamplesabove,youmayreplace"npm"with"yarn"or"pnpm".
KeywordsbashconcurrentparallelconcurrentlycommandshInstallnpmiconcurrentlyRepositoryGitgithub.com/open-cli-tools/concurrentlyHomepagegithub.com/open-cli-tools/concurrently#readmeDownloadsWeeklyDownloads2,181,037Version6.3.0LicenseMITUnpackedSize104kBTotalFiles39LastpublishamonthagoCollaboratorsTryonRunKitReportmalware