YApi serves as an efficient, open-source interface management platform designed to assist developers, product managers, and testers in creating, publishing, and maintaining APIs. Setting up YApi on a local Windows environment requires a specific stack and configuration process.
Prerequisites
Before initiating the deployment, ensure the following software is installed and configured on the system:
- Node.js (LTS version recommended)
- MongoDB (Database service)
- Git (Version control)
Source Code Acquisition
Obtain the source code from the official GitHub repository or a mirror repository if network speed is an issue.
git clone https://github.com/YMFE/yapi.gitAlternatively, use the Gitee mirror:
git clone https://gitee.com/mirrors/YApi.gitInstallation and Configuration
Navigate to the project root directory. Install the YApi command-line interface tool globally to facilitate the visual deployment process.
npm install -g yapi-cliOnce installed, start the configuration server.
yapi serverIf the browser does not load the page correctly at localhost:9090, try running the server command without specific registry flags or check network proxy settings.
Access the deployment interface via a web browser at http://localhost:9090. Follow the on-screen wizard to input database connection details (MongoDB) and set administrator credentials. Upon successful submission, the system will compile the necessary files.
After the deployment script finishes, navigate to the output directory specified during configuration (default is often the current directory or a subfolder named yapi). Start the application server using Node.js:
node vendors/server/app.jsThe platform should now be accessible at http://localhost:3000.
Process Management with PM2
Running the application directly via the Node command binds the process to the current terminal session. Closing the window terminates the service. To ensure the service runs persistently in the background, use PM2 for process management.
First, install PM2 globally:
npm install -g pm2Change into the YApi deployment directory and start the service with a custom name for easier identification:
pm2 start vendors/server/app.js --name yapi-serverThe service is now managed by PM2 and will restart automatically if it crashes or if the system reboots (provided PM2 startup scripts are configured). Common PM2 commands for managing the instance include:
pm2 list # View all running processes
pm2 info yapi-server # Display detailed process information
pm2 stop yapi-server # Stop the service
pm2 restart yapi-server # Restart the service