Overview
The Tandex Electronics API is an Express.js-based REST API service that provides product management, user authentication, and WooCommerce integration capabilities.System Requirements
Before you begin, ensure you have the following installed:- Node.js: Version 12.x or higher (compatible with the dependencies)
- MySQL: Version 5.7 or higher
- npm: Version 6.x or higher
Installation
Install dependencies
Install all required npm packages:This will install the following key dependencies:
express- Web frameworkmysql- Database driverjsonwebtoken- JWT authenticationbcrypt- Password hashing@woocommerce/woocommerce-rest-api- WooCommerce integrationcors- Cross-origin resource sharingmorgan- HTTP request logger
Configure environment variables
Create a
config/default.json file in the project root with your configuration:Set up the database
Import the database schema from See the Database Configuration guide for detailed setup instructions.
backend.sql:Server Configuration
The server is configured inserver.js with the following settings:
server.js
Key Features
- CORS enabled: Allows cross-origin requests from any domain
- Request logging: Morgan middleware logs all HTTP requests in development mode
- JSON payload: Supports up to 100MB JSON payloads
- Cache control: Prevents browser caching with appropriate headers
- Port configuration: Uses
PORTenvironment variable or defaults to 8080
Verifying the Installation
Once the server is running, verify the installation:- Check the console output for any errors
- The server should be listening on the configured port (default: 8080)
- Test the API endpoint:
If you encounter any connection errors, verify that:
- MySQL is running and accessible
- Database credentials in
config/default.jsonare correct - The database schema has been imported successfully
Port Configuration
The server port can be configured in two ways:-
Environment variable: Set the
PORTenvironment variable -
Config file: Modify the
portvalue inconfig/default.json
The environment variable
PORT takes precedence over the config file setting.