Autoplay

    Open Multiple Terminal Tabs on npm Start with ttab and npm-run-all

    Sergii ShvagerSergii Shvager

    Often times when developing web applications, you need to open multiple tabs to run different scripts to start the application. This can all be done with one command

    In this lesson, you will learn how to start a project and open multiple terminal tabs with one npm script.

    Valid for macOS users.

    npmnpm
    nodeNode.js
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: 00:00 Let's imagine you have a project with a Java back end and Webpack Dev Server. Every time you would like to start the project, you need to run these two NPM scripts in different terminal tabs. Here, we started Webpack Dev Server, and here, we started our back end. Then we need to open website in the browser.

    00:22 We're going to automate project start with NPM scripts. To solve this, we're going to use Ttab and npm-run-all packages. First, let's create new NPM script that runs command in new tab. Ttab expects command that you want to run in a new tab.

    00:46 With a navigation terminal, we can add title for each tab. Second, let's create script that opens website in the browser. Third, let's create start script that we're going to use to start the project. To run sequentially all three commands, we are using run-as command.

    01:08 That comes with the npm-run-all package. Now, let's test it. With one npm start, we are able to run two new tabs. With a back end that has Java server title, our Webpack Dev Server with a build JS title, and website in the browser.

    Discuss

    Discuss