node-consul-service 1.0.45 → 1.0.46

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 +55 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -6,7 +6,7 @@ A robust Node.js service that integrates with HashiCorp Consul for service disco
6
6
  - [Features](#features)
7
7
  - [Prerequisites](#prerequisites)
8
8
  - [Installation](#installation)
9
- - [Configuration](#configuration)
9
+ - [Initialization](#initialization)
10
10
  - [API Documentation](#api-documentation)
11
11
  - [Examples](#examples)
12
12
  - [Contributing](#contributing)
@@ -35,16 +35,62 @@ npm install node-consul-service
35
35
  yarn add node-consul-service
36
36
  ```
37
37
 
38
- ## Configuration
38
+ ## Initialization
39
39
 
40
- Create a `.env` file in your project root with the following variables:
40
+ ### Service Initialization
41
41
 
42
- ```env
43
- CONSUL_HOST=your-consul-host
44
- CONSUL_PORT=8500
45
- CONSUL_SECURE=false
46
- CONSUL_TOKEN=your-consul-token # Optional
47
- CONSUL_DC=your-datacenter # Optional
42
+ Before using any functions from the library, you must initialize the client first. You can initialize the client by passing configuration options:
43
+
44
+ ```javascript
45
+ const { initClient } = require('node-consul-service');
46
+
47
+ await initClient({
48
+ host: 'localhost',
49
+ port: 8500,
50
+ secure: false,
51
+ token: 'your-token', // Optional
52
+ datacenter: 'dc1', // Optional
53
+ retryAttempts: 3, // Number of connection retry attempts
54
+ retryDelay: 1000 // Delay between retries in milliseconds
55
+ });
56
+ ```
57
+
58
+ ### Initialization Features
59
+
60
+ - **Automatic Retry**: Attempts to connect multiple times on failure
61
+ - **Connection Verification**: Verifies successful connection before proceeding
62
+ - **State Management**: Tracks initialization state to prevent multiple initializations
63
+ - **Error Handling**: Clear and helpful error messages
64
+
65
+ ### Complete Usage Example
66
+
67
+ ```javascript
68
+ const { initClient, registerService } = require('node-consul-service');
69
+
70
+ async function startService() {
71
+ try {
72
+ // Initialize client
73
+ await initClient({
74
+ host: 'localhost',
75
+ port: 8500,
76
+ retryAttempts: 3
77
+ });
78
+
79
+ // Register service
80
+ await registerService({
81
+ name: 'my-service',
82
+ id: 'my-service-1',
83
+ port: 3000
84
+ });
85
+
86
+ console.log('✅ Service started successfully');
87
+ } catch (error) {
88
+ console.error('❌ Failed to start service:', error);
89
+ process.exit(1);
90
+ }
91
+ }
92
+
93
+ startService();
48
94
  ```
49
95
 
50
96
  ## API Documentation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-consul-service",
3
- "version": "1.0.45",
3
+ "version": "1.0.46",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",