Home
Forums
New posts
Search forums
What's new
New posts
New resources
New profile posts
Latest activity
Resources
Latest reviews
Search resources
Members
Current visitors
New profile posts
Search profile posts
DMCA Policy
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
FEEL FREE TO SHARE TUTORIALS, YOUR SKILS & KNOWLEDGE ON CODING, SCRIPTS, THEMES, PLUGINS OR ANY RESOURCES YOU HAVE WITH THE COMMUNITY-
Click Here To Post Your Request,
JOIN COMPUTER REPAIR FORUM
Home
Forums
TUTORIALS
CODING TUTORIALS
Node.js
Node.js Port Scanner
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="codeguru" data-source="post: 57" data-attributes="member: 2"><p>Node.js has become an incredible tool for creating services or utilities that act like a service. Usually it’s [ICODE]npm start[/ICODE], wait a moment, and you’ll see the utility provide an address and port; a good example being [ICODE]localhost:8000[/ICODE]. One thing that bugs me about this pattern is if you have many service-based utilities that you work on, you wind up running into “port in use” errors, after which you need to look through all of your utilities to see which one to turn off.</p><p></p><p>There’s an easy solution to this problem: <a href="https://github.com/baalexander/node-portscanner" target="_blank">Node Port Scanner</a>. This utility provides methods for finding in use or available ports on a given host!</p><p></p><h2>Using Port Scanner</h2><p></p><p>The most common use case to solve port collisions would be [ICODE]findAPortNotInUse[/ICODE]:</p><p></p><p></p><p>var portscanner = require('portscanner');</p><p></p><p>// 127.0.0.1 is the default hostname; not required to provide</p><p>portscanner.findAPortNotInUse([3000, 3010], '127.0.0.1').then(port => {</p><p> console.log(`Port ${port} is available!`);</p><p></p><p> // Now start your service on this port...</p><p>});</p><p></p><p></p><p>Providing a series of ports and then starting on the first available port is made simple — no more collisions.</p><p></p><p>You can also check for a given port’s status, or check for ports in use:</p><p></p><p></p><p>// Get port status</p><p>portscanner.checkPortStatus(3000, '127.0.0.1').then(status => {</p><p> // Status is 'open' if currently in use or 'closed' if available</p><p> console.log(status);</p><p>});</p><p></p><p>// Find port in use</p><p>portscanner.findAPortInUse([3000, 3005, 3006], '127.0.0.1').then(port => {</p><p> console.log('PORT IN USE AT: ' + port);</p><p>});</p><p></p><p></p><p>Using this port scanner utility is incredibly simple and the easiest way to get your service to run on any available port. Hardcoded port usage, when unnecessary, only leads to frustration!</p><p></p><p>The post <a href="https://davidwalsh.name/javascript-port-scanner" target="_blank">Node.js Port Scanner</a> appeared first on <a href="https://davidwalsh.name" target="_blank">David Walsh Blog</a>.</p><p></p><p><a href="https://tkjs.us/dwb" target="_blank"><img src="https://davidwalsh.name/demo/tjs_block-1.svg" alt="" class="fr-fic fr-dii fr-draggable " style="" /></a></p><p></p><p><a href="https://davidwalsh.name/javascript-port-scanner" target="_blank">Continue reading...</a></p></blockquote><p></p>
[QUOTE="codeguru, post: 57, member: 2"] Node.js has become an incredible tool for creating services or utilities that act like a service. Usually it’s [ICODE]npm start[/ICODE], wait a moment, and you’ll see the utility provide an address and port; a good example being [ICODE]localhost:8000[/ICODE]. One thing that bugs me about this pattern is if you have many service-based utilities that you work on, you wind up running into “port in use” errors, after which you need to look through all of your utilities to see which one to turn off. There’s an easy solution to this problem: [URL='https://github.com/baalexander/node-portscanner']Node Port Scanner[/URL]. This utility provides methods for finding in use or available ports on a given host! [HEADING=1]Using Port Scanner[/HEADING] The most common use case to solve port collisions would be [ICODE]findAPortNotInUse[/ICODE]: var portscanner = require('portscanner'); // 127.0.0.1 is the default hostname; not required to provide portscanner.findAPortNotInUse([3000, 3010], '127.0.0.1').then(port => { console.log(`Port ${port} is available!`); // Now start your service on this port... }); Providing a series of ports and then starting on the first available port is made simple — no more collisions. You can also check for a given port’s status, or check for ports in use: // Get port status portscanner.checkPortStatus(3000, '127.0.0.1').then(status => { // Status is 'open' if currently in use or 'closed' if available console.log(status); }); // Find port in use portscanner.findAPortInUse([3000, 3005, 3006], '127.0.0.1').then(port => { console.log('PORT IN USE AT: ' + port); }); Using this port scanner utility is incredibly simple and the easiest way to get your service to run on any available port. Hardcoded port usage, when unnecessary, only leads to frustration! The post [URL='https://davidwalsh.name/javascript-port-scanner']Node.js Port Scanner[/URL] appeared first on [URL='https://davidwalsh.name']David Walsh Blog[/URL]. [URL='https://tkjs.us/dwb'][IMG]https://davidwalsh.name/demo/tjs_block-1.svg[/IMG][/URL] [url="https://davidwalsh.name/javascript-port-scanner"]Continue reading...[/url] [/QUOTE]
Insert quotes…
Verification
Post reply
Richest Freecoded User
Most Freecoin
freecoded
4,838 Freecoin
Davy200
590 Freecoin
J
Johnhendrick
575 Freecoin
S
Smith16
527 Freecoin
nathan69
426 Freecoin
Laureine
415 Freecoin
A
anajeen
370 Freecoin
C
codeguru
287 Freecoin
Tekera
267 Freecoin
A
Akubay
170 Freecoin
Home
Forums
TUTORIALS
CODING TUTORIALS
Node.js
Node.js Port Scanner
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top