npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

api-crafter

v1.0.10

Published

An Advanced Api Crafting Package On Beta Stage

Downloads

18

Readme

API Crafter

API Crafter Logo

API Crafter is a versatile Node.js package designed by adithyadev_blk for crafting robust and scalable APIs effortlessly. With Express.js integration, customizable middleware, API key management, error handling, analytics, and extensibility, API Crafter provides a comprehensive solution for building APIs.

Features

Express.js Integration

API Crafter seamlessly integrates with Express.js, facilitating the handling of HTTP requests and responses.

Middleware Configuration

  • Rate Limiting: Limit the number of requests from a client within a specified time frame.
  • Logging: Log incoming requests and responses for better debugging and monitoring.
  • CORS Support: Handle Cross-Origin Resource Sharing to allow or restrict access to the API from different origins.
  • Maintenance Mode: Toggle maintenance mode to return a service unavailable message to clients when enabled.

API Key Management

  • Generation: Generate API keys dynamically.
  • Verification: Verify API keys for authentication.
  • Deletion: Delete existing API keys as needed.

Error Handling

  • Customizable Error Messages: Customize error messages for unauthorized access and other errors.

Analytics

  • Request Logging: Log details of incoming requests, including timestamp, HTTP method, URL, and client IP address.
  • Analytics Endpoint: Access request analytics data through a dedicated endpoint (/analytics).

Customizable Options

  • Project Name: Customize the project name displayed in console logs.
  • Port: Define the port number on which the server listens.
  • Rate Limiting Configuration: Customize window duration, maximum requests per window, and rate limit exceeded message.
  • Maintenance Mode Configuration: Customize the maintenance mode message.
  • CORS Configuration: Customize allowed origins and HTTP methods for CORS.
  • Error Message Configuration: Customize error messages for unauthorized access and other errors.

Dynamic Functionality

  • Maintenance Mode Toggle: Dynamically toggle maintenance mode on/off for testing purposes.
  • Simple API Definition: Easily define API routes and their corresponding handlers using simple methods (get, post, delete, etc.).

Server Start

  • Start Command: Start the Express server and listen on the specified port, displaying console logs indicating server status.

Package Extensibility

API Crafter is designed to be easily extensible, allowing users to add additional features and customize functionality as needed.

Usage Examples

// Example usage of the extended API Crafter package

const API = require('./api-cre');

// Define options for API initialization
const options = {
  projectName: 'My API',
  port: 3000,
  rateLimit: {
    windowMs: 60 * 1000, // 1 minute
    max: 10, // 10 requests per minute
    message: 'Custom rate limit exceeded message: Too many requests',
  },
  logging: true,
  cors: {
    origin: '*', // Allow requests from any origin
    methods: 'GET,POST',
  },
  error: 'Custom unauthorized access message: You are not authorized to access this resource',
  maintenanceMessage: 'Custom maintenance message: Service is currently under maintenance. Please try again later.',
};

// Initialize API with options
const myAPI = new API(options);

// Generate API key
const apiKey = myAPI.generateAPIKey();
console.log('Generated API Key:', apiKey);

// Verify API key (Example with a valid API key)
console.log('Verification with a valid API Key:', myAPI.verifyAPIKey(apiKey));

// Verify API key (Example with an invalid API key)
const invalidKey = 'invalid-api-key';
console.log('Verification with an invalid API Key:', myAPI.verifyAPIKey(invalidKey));

// Delete API key
console.log('API Key before deletion:', myAPI.verifyAPIKey(apiKey));
myAPI.deleteAPIKey(apiKey);
console.log('API Key after deletion:', myAPI.verifyAPIKey(apiKey));

// Define routes
myAPI.get('/', (req, res) => {
  res.send('Hello World!');
});

// Route requiring authentication
myAPI.get('/protected', myAPI.auth, (req, res) => {
  res.send('This is a protected route.');
});

// Maintenance mode route
myAPI.get('/maintenance', (req, res) => {
  if (myAPI.maintenanceMode) {
    res.send('Maintenance mode is currently enabled.');
  } else {
    res.send('Maintenance mode is currently disabled.');
  }
});

// Toggle maintenance mode route (for testing purposes)
myAPI.post('/maintenance/toggle', (req, res) => {
  myAPI.maintenanceMode = !myAPI.maintenanceMode;
  res.send(`Maintenance mode toggled ${myAPI.maintenanceMode ? 'ON' : 'OFF'}.`);
});

// Error handling middleware
myAPI.app.use((err, req, res, next) => {
  console.error(err);
  res.status(err.status || 500).json({ error: err.message || 'Internal Server Error' });
});

// Start the server
myAPI.start();

Author and License

API Crafter is created by adithyadev_blk and is available for everyone to use.