
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
node-consul-service
Advanced tools
A robust Node.js service that integrates with HashiCorp Consul for service discovery and configuration management. This service provides a comprehensive solution for managing distributed systems and microservices architecture, making it easier to handle s
A robust Node.js service that integrates with HashiCorp Consul for service discovery and configuration management. This service provides a comprehensive solution for managing distributed systems and microservices architecture, making it easier to handle service communication, health checks, and configuration management in a distributed environment.
# Using npm
npm install node-consul-service
# Using yarn
yarn add node-consul-service
Before using any functions from the library, you must initialize the client first. You can initialize the client by passing configuration options:
const { initClient } = require('node-consul-service');
await initClient({
host: 'localhost',
port: 8500,
secure: false,
token: 'your-token', // Optional
datacenter: 'dc1', // Optional
retryAttempts: 3, // Number of connection retry attempts
retryDelay: 1000 // Delay between retries in milliseconds
});
const { initClient, registerService } = require('node-consul-service');
async function startService() {
try {
// Initialize client
await initClient({
host: 'localhost',
port: 8500,
retryAttempts: 3
});
// Register service
await registerService({
name: 'my-service',
id: 'my-service-1',
port: 3000
});
console.log('✅ Service started successfully');
} catch (error) {
console.error('❌ Failed to start service:', error);
process.exit(1);
}
}
startService();
const { registerService } = require('node-consul-service');
await registerService({
name: 'service-name',
id: 'service-id',
port: 3000,
address: 'localhost',
check: {
name: 'service health check',
http: 'http://localhost:3000/health',
interval: '10s',
timeout: '5s',
deregistercriticalserviceafter: '1m'
}
});
const { callService } = require('node-consul-service');
// Simple GET request
const result = await callService('service-name', '/endpoint');
// POST request with data
const response = await callService('service-name', {
method: 'POST',
path: '/endpoint',
data: { key: 'value' }
});
const {
listServices,
getServiceInstances,
getRandomServiceInstance
} = require('node-consul-service');
// List all registered services
const services = await listServices();
// Get all instances of a specific service
const instances = await getServiceInstances('service-name');
// Get a random instance of a service
const instance = await getRandomServiceInstance('service-name');
The dataLink
function provides a powerful way to aggregate and link data from multiple services efficiently.
const { dataLink } = require('node-consul-service');
const data = [
{ userId: '123', name: 'John' },
{ userId: '456', name: 'Jane' }
];
const schema = [
{
Field: 'userId', // Field name in the original data
service: 'user-service', // Target service name
path: '/api/users/batch', // API endpoint path
cacheGetter: async (ids) => {
// Optional function to get data from cache
return await cache.getUsers(ids);
}
}
];
const result = await dataLink(data, schema);
Field
: Field name in the original data that contains the identifierservice
: Name of the service to be calledpath
: API endpoint path in the target servicecacheGetter
: Optional function to get data from cache before calling the serviceconst { registerService, callService } = require('node-consul-service');
// Register your service
await registerService({
name: 'my-service',
id: 'my-service-1',
port: 3000,
address: 'localhost',
check: {
http: 'http://localhost:3000/health',
interval: '10s'
}
});
// Call another service
const response = await callService('other-service', '/api/data');
const { dataLink } = require('node-consul-service');
// Complex data linking example
const orders = [
{ orderId: '1', userId: '123', productId: 'P1' },
{ orderId: '2', userId: '456', productId: 'P2' }
];
const schema = [
{
Field: 'userId',
service: 'user-service',
path: '/api/users/batch'
},
{
Field: 'productId',
service: 'product-service',
path: '/api/products/batch'
}
];
const enrichedOrders = await dataLink(orders, schema);
We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A robust Node.js service that integrates with HashiCorp Consul for service discovery and configuration management. This service provides a comprehensive solution for managing distributed systems and microservices architecture, making it easier to handle s
The npm package node-consul-service receives a total of 389 weekly downloads. As such, node-consul-service popularity was classified as not popular.
We found that node-consul-service demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.