Overview
React Route Finder uses Node.js and npm to manage dependencies and build processes. This guide covers the complete environment setup including dependencies, scripts, and backend configuration.Dependencies
Core Dependencies
The application requires the following core dependencies:React & React DOM: Version 16.3.2 provides the UI framework for the applicationExpress: Powers the backend server for route calculations and API endpointsWebpack & Babel: Handle code bundling and JSX/ES6 transpilation
Development Dependencies
- concurrently: Runs multiple npm scripts simultaneously (frontend + backend)
- nodemon: Auto-restarts the server on file changes during development
Installation
Install Node.js
Ensure you have Node.js installed (version 8.x or higher recommended for this setup)
Install Dependencies
Navigate to the project directory and install all dependencies:This installs both production and development dependencies defined in package.json
NPM Scripts
The project includes several npm scripts for different development and production workflows:Development Scripts
npm run dev
Runs webpack in development mode with watch enabled:
- Uses webpack development mode (
-dflag) - Watches for file changes and auto-rebuilds
- Generates source maps for easier debugging
- Output files are written to the
public/directory
npm run serverDev
Starts the Express server with auto-restart on changes:
- Uses nodemon to watch server files
- Automatically restarts when server code changes
- Listens on port 8080 by default
npm start
The complete development workflow that runs both webpack and server concurrently:
npm run dev and npm run serverDev simultaneously using concurrently. This is the recommended command for active development.
The
--kill-others flag ensures that if one process fails, all processes are terminated. This prevents orphaned processes.Production Scripts
npm run build
Creates an optimized production build:
- Uses webpack production mode (
-pflag) - Minifies and optimizes JavaScript code
- Generates optimized bundles in the
public/directory - No source maps (smaller file sizes)
npm run server
Runs the Express server in production mode:
npm run build to serve the production application.
Server Configuration
Port Configuration
The Express server runs on port 8080 by default. To change this, modifysrc/server/server.js:
Backend URL Configuration
The application usesServerMockup to simulate backend data. In production, you’ll need to replace this with actual API calls.
API Endpoints
The Express server exposes the following endpoints:- GET /allRoutes: Returns all available bus routes and stops
- POST /route: Calculates the optimal route based on origin and destination