So, a 'service' is a logical human thing, not a fixed, networking thing.
The items in /etc/services are just a handy 'commonly used' mapping, but
aren't strictly or adhered to or used to configure the applications on your
host. You can listen to HTTP on port 1337 just as well as you can on port
80 (with proper permissions). You can get the ports that a *currently
running* process is using, but I don't think that helps you.
It seems you're trying to listen to a port and respond with HTTP traffic. A
common pattern to dynamically choose the port to listen to is with
environment variables.
var server = http.createServer();
server.listen(process.env.PORT, function () {
...
}
And then start the application by specifying the port on the command line:
$ PORT=1337 node server.js
This lets you change the port easily without modifying the code or run
multiple copies of your server listening to different ports at the same
time.
HTH,
Mikkel
On Wednesday, March 21, 2018 at 9:49:35 AM UTC-7, Jean Marie wrote:
>
> Hello
>
> I use the method createServer from class http and then listen to a port as
> follows :
>
> var server = http.createServer();
> server.listen(port, function () {
> ...
> }
>
> the problem is that I only have the service name
> and listening to a service doesn't work :
>
> var server = http.createServer();
> server.listen(service, function () {
> ...
> }
>
>
> so I need to read and parse the file /etc/services to get the port
> associated with the service
>
> is there a simpler way to get the port from the service ?
>
> thanks in advance
>
> Jean-Marie
>
>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/b8e89af8-cc3e-4bb2-aa4f-cbd69648ce84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.