How to Create a Windows Batch Script to Start/Run a Server
This guide shows how to automate your development workflow by creating Windows batch scripts.
The Problem: Repetitive Morning Routine
Every morning when I start work, I need to run the same set of commands to launch my local development servers and open all the necessary tools. Manually doing this routine became tedious, so I decided to automate it using Windows batch scripts.
My Development Environment Needs
I work with three different projects, each requiring different setup commands:
-
React - Needs Node.js server
-
Django - Needs Python virtual environment and server
-
Laravel - Needs Docker containers
For each project, I need to:
-
Run the local development server
-
Open a web browser to the development site or admin panel
-
Launch Visual Studio Code in the project directory
The Solution: Batch Script Automation
I created separate .bat files for each project saved on my desktop. Each script:
-
Disables command echoing for cleaner output
-
Starts the development server in a new command window
-
Opens the relevant browser tabs
-
Launches VS Code in the project directory
React Project Batch Script
`@echo off
start cmd.exe /k "cd Projects/react-project && npm run start"
start chrome http://localhost:8080/
code -n Projects\react-project`
Django Project Batch Script
`@echo off
start cmd.exe /k "cd Projects && django_virtual_env\Scripts\activate && cd django-project && py manage.py runserver 8000"
start chrome http://127.0.0.1:8000/
start firefox http://127.0.0.1:8000/admin/
code -n Projects\django-project`
Laravel Project Batch Script
`@echo off
start cmd.exe /k "cd Projects && open -a Docker cd laravel-project && docker compose up -d"
start chrome http://localhost:80/
start firefox http://localhost:8080/phpmyadmin
code -n Projects\laravel-project`
The Result: One-Click Project Setup
Now instead of manually running all these commands every morning, I simply double-click the appropriate batch file on my desktop. Each script handles the complete setup for its respective project, saving me time and ensuring consistency in my development environment.