node-consul-service 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +36 -57
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -5,87 +5,66 @@ A Node.js service that integrates with HashiCorp Consul for service discovery an
5
5
  ### Features
6
6
  - Service registration and discovery
7
7
  - Health checking
8
- - Key-value store integration
9
- - Configuration management
10
- - Distributed locking
11
- - Leader election
8
+ - Service communication
9
+ - Service instance management
12
10
 
13
11
  ### Prerequisites
14
12
  - Node.js (v14 or higher)
15
13
  - Consul server
16
- - npm or yarn
14
+ - npm
17
15
 
18
16
  ### Installation
19
17
  ```bash
20
- # Clone the repository
21
- git clone https://github.com/your-username/node-consul-service.git
22
-
23
- # Navigate to project directory
24
- cd node-consul-service
25
-
26
- # Install dependencies
27
- npm install
18
+ npm install node-consul-service
28
19
  ```
29
20
 
30
21
  ### Configuration
31
- Create a `.env` file in the root directory with the following variables:
22
+ Create a `.env` file in your project root with the following variables:
32
23
  ```env
33
- CONSUL_HOST=localhost
24
+ CONSUL_HOST=your-consul-host
34
25
  CONSUL_PORT=8500
35
- SERVICE_NAME=my-service
36
- SERVICE_PORT=3000
37
- ```
38
-
39
- ### Usage
40
- ```bash
41
- # Start the service
42
- npm start
43
-
44
- # Run tests
45
- npm test
26
+ CONSUL_SECURE=false
46
27
  ```
47
28
 
48
29
  ### Function Usage
49
30
  Here are the main functions available in the service:
50
31
 
51
32
  ```javascript
52
- // Service Registration
53
- const service = new ConsulService({
54
- name: 'my-service',
55
- port: 3000
33
+ const {
34
+ registerService,
35
+ callService,
36
+ listServices,
37
+ getServiceInstances,
38
+ getRandomServiceInstance
39
+ } = require('node-consul-service');
40
+
41
+ // Register a new service
42
+ await registerService({
43
+ name: 'service-name',
44
+ id: 'service-id',
45
+ port: 3000,
46
+ address: 'localhost',
47
+ check: {
48
+ name: 'service health check',
49
+ http: 'http://localhost:3000/health',
50
+ interval: '10s',
51
+ timeout: '5s',
52
+ deregistercriticalserviceafter: '1m'
53
+ }
56
54
  });
57
- await service.register();
58
-
59
- // Service Discovery
60
- const services = await service.discover('service-name');
61
55
 
62
- // Key-Value Operations
63
- await service.setKey('config/key', 'value');
64
- const value = await service.getKey('config/key');
56
+ // Call another service
57
+ const result = await callService('service-name', '/endpoint');
65
58
 
66
- // Health Check
67
- await service.checkHealth();
59
+ // List all registered services
60
+ const services = await listServices();
68
61
 
69
- // Distributed Lock
70
- const lock = await service.acquireLock('resource-name');
71
- if (lock) {
72
- // Perform locked operations
73
- await service.releaseLock('resource-name');
74
- }
62
+ // Get all instances of a specific service
63
+ const instances = await getServiceInstances('service-name');
75
64
 
76
- // Leader Election
77
- await service.startLeaderElection('election-key');
78
- service.on('leader', () => {
79
- // Handle leader election
80
- });
65
+ // Get a random instance of a service
66
+ const instance = await getRandomServiceInstance('service-name');
81
67
  ```
82
68
 
83
- ### Contributing
84
- 1. Fork the repository
85
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
86
- 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
87
- 4. Push to the branch (`git push origin feature/amazing-feature`)
88
- 5. Open a Pull Request
89
-
90
69
  ### License
91
70
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-consul-service",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",