@caboodle-tech/node-simple-server 4.2.2 → 4.2.4

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 (3) hide show
  1. package/README.md +6 -2
  2. package/bin/nss.js +28 -8
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -283,6 +283,10 @@ With your new instance of NSS you can call any of the following public methods:
283
283
 
284
284
  - Send a message (`msg`) via WebSocket to the page that matches the `pageId`, or send to a page or pages that match the `pattern`.
285
285
 
286
+ ### **printListeningAddresses(\[returnInstead = false\])**
287
+
288
+ - Prints a message to console with all the addresses the server is available at. If you want full control of the printing you can set `returnInstead` to `true`.
289
+
286
290
  #### **reloadPages()**
287
291
 
288
292
  - Sends the reload signal to all active pages.
@@ -303,9 +307,9 @@ With your new instance of NSS you can call any of the following public methods:
303
307
 
304
308
  - Unregister (stop messaging) a `callback` function that was initially registered with the `pattern`.
305
309
 
306
- #### **start(\[callback\]) | start(\[port\], \[callback\])**
310
+ #### **start(\[callback\]) | start(\[port\], \[callback\], [printAddresses=true])**
307
311
 
308
- - Starts the HTTP and WebSocket servers and notifies `callback` if present. `Port` is meant to be an internal option for NSS only but you may specify a port number for NSS to use if you have strict requirements in your environment. NOTE: This is a blocking process and will keep any application that ran it alive until stopped gracefully or forcefully terminated. If you do not want this behavior for any reason you will need to call this in its own process.
312
+ - Starts the HTTP and WebSocket servers and notifies `callback` if present. `Port` is meant to be an internal option for NSS only but you may specify a port number for NSS to use if you have strict requirements in your environment. NOTE: This is a blocking process and will keep any application that ran it alive until stopped gracefully or forcefully terminated. If you do not want this behavior for any reason you will need to call this in its own process. Set `printAddresses` to `false` if you want to hide or print the server address on your own.
309
313
 
310
314
  #### **stop(\[callback\])**
311
315
 
package/bin/nss.js CHANGED
@@ -44,7 +44,7 @@ class NodeSimpleServer {
44
44
  map: {}
45
45
  };
46
46
 
47
- #VERSION = '4.2.1';
47
+ #VERSION = '4.2.4';
48
48
 
49
49
  #watching = [];
50
50
 
@@ -373,6 +373,27 @@ class NodeSimpleServer {
373
373
  };
374
374
  }
375
375
 
376
+ /**
377
+ * Print the addresses the server is listening on to the console; this is useful for users who
378
+ * are not sure what address to use to access the server.
379
+ *
380
+ * @param {boolean} [returnInstead=false] If true the function will return the message string instead.
381
+ */
382
+ // eslint-disable-next-line consistent-return
383
+ printListeningAddresses(returnInstead = false) {
384
+ let message = 'Node Simple Server live @:\n';
385
+ const addresses = this.getAddresses(this.#OPS.port);
386
+ addresses.forEach((address) => {
387
+ message += ` ${address}\n`;
388
+ });
389
+ message += '\n';
390
+
391
+ if (returnInstead) {
392
+ return message;
393
+ }
394
+ Print.notice(message);
395
+ }
396
+
376
397
  /**
377
398
  * Converts a regular expression (regex) string into an actual RegExp object.
378
399
  *
@@ -859,9 +880,11 @@ class NodeSimpleServer {
859
880
  * this, it's meant to be used internally to NSS.
860
881
  * @param {function} [callback] Optional function to call when the server successfully starts
861
882
  * (true) or gives up on trying to start (false);
883
+ * @param {boolean} [printAddresses=true] If true the server will print out all the
884
+ * addresses it is listening on.
862
885
  * @return {void} Used only as a short circuit.
863
886
  */
864
- start(port, callback) {
887
+ start(port, callback, printAddresses = true) {
865
888
 
866
889
  // Port is usually internal to NSS so check if a user placed the callback first.
867
890
  if (port && typeof port === 'function') {
@@ -952,12 +975,9 @@ class NodeSimpleServer {
952
975
  this.#OPS.portInUse = port;
953
976
 
954
977
  // Log the ip addresses being watched.
955
- Print.notice('Node Simple Server live @:');
956
- const addresses = this.getAddresses(port);
957
- addresses.forEach((address) => {
958
- Print.notice(` ${address}`);
959
- });
960
- Print.log('');
978
+ if (printAddresses) {
979
+ this.printListeningAddresses(port);
980
+ }
961
981
 
962
982
  // Notify the callback.
963
983
  if (callback) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caboodle-tech/node-simple-server",
3
- "version": "4.2.2",
3
+ "version": "4.2.4",
4
4
  "description": "Node Simple Server (NSS): A small but effective node based server for development sites, customizable live reloading, and websocket support built-in.",
5
5
  "main": "bin/nss.js",
6
6
  "scripts": {