socket-api-extractor v0.0.1
Socket API Extractor
Socket API Extractor is a simple npm package designed to automatically extract and list all your socket events and API routes from your backend codebase. This package scans your server.js
file (or any other specified file) and outputs a list of all the socket events and API routes used in your application.
Features
- Extracts all
socket.emit()
andsocket.on()
events. - Lists all
api
endpoints defined in your backend code. - Works with Express.js and Socket.IO codebases.
- Outputs a clean, easy-to-read list of API routes and socket events.
Installation
To install the socket-api-extractor
package, run the following command:
npm install socket-api-extractor
Usage
Extract Socket Events and API Routes from Your Backend Code
- Create a
server.js
(or specify your server entry file). - Use the package in a script to automatically extract all your socket events and API routes.
Example Usage
Create a new JavaScript file (e.g., extract.js
) in your project, and add the following code:
const { extractSocketEvents, extractApiRoutes } = require('socket-api-extractor');
// Specify the path to your server file (default is './server.js')
const serverFilePath = './server.js';
// Extract and print socket events
extractSocketEvents(serverFilePath).then((socketEvents) => {
console.log('Socket Events:', socketEvents);
});
// Extract and print API routes
extractApiRoutes(serverFilePath).then((apiRoutes) => {
console.log('API Routes:', apiRoutes);
});
Output
After running the script, you'll see the extracted socket events and API routes printed to your console.
For example:
Socket Events:
- socket.emit('message', data)
- socket.on('chatMessage', callback)
- io.sockets.emit('userConnected', userId)
API Routes:
- POST /api/login
- GET /api/users
- PUT /api/updateProfile
Running the Script
To run your script, simply execute the following command:
node extract.js
Customization
You can customize the behavior of the extractor by:
- Changing the path of the server file.
Specifying a custom file if your server code is not in
server.js
.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributors
Contributing
Feel free to contribute! You can open an issue or submit a pull request with improvements or bug fixes.
Acknowledgments
- Thanks to the contributors of Express.js and Socket.IO for making these technologies widely used and easy to integrate into your applications!