Create .bat file to open Node.js terminal and execute one or more commands

Question:

I would like to create a .bat file to automate a process I have to perform every day.

Whenever I start working, I open the nodejs terminal, access my project directory (in my case I use babel) and then I need to run the command npm run babel .

The problem is, I work on more than one project. Then sometimes I have to navigate through the terminal to the directory and then I need to run the command to start babel.

I would like to create a .bat file for each project, to leave everything configured and when I click on the .bat file of the project I want, it opens nodejs terminal and executes the commands I want. It is possible?

Answer:

Just create a file iniciar_projeto.bat with something like:

cd C:\Users\Alan\Documentos\Seu_Projeto\
npm run babel

The first command should obviously be changed to your project path. This is enough to run the server, if everything is set up correctly.

If the .bat is on D: and your project is on drive C:, you need to change volume first:

c:
cd C:\Users\Alan\Documentos\Seu_Projeto\
npm run babel
Scroll to Top