서버(Server)/Server&Nodejs&DB
Node.js server.listen() Method
3DMP
2018. 7. 23. 20:41
Example
Create a server that listens on port 8080 of your computer.
When port 8080 get accessed, write "Hello World!" back as a response:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World!');
res.end();
}).listen(8080);
Definition and Usage
The server.listen() method creates a listener on the specified port or path.
Syntax
server.listen(port, hostname, backlog, callback);
Parameter Values
Parameter | Description |
---|---|
port | Optional. Specifies the port we want to listen to |
hostname | Optional. Specifies the IP address we want to listen to |
backlog | Optional. Specifies the max length of the queue of pending connections. Default 511 |
callback | Optional. Specifies a function to be executed when the listener has been added |
Technical Details
Return Value: | None |
---|---|
Node.js Version: | 0.1.90 |
ref : https://www.w3schools.com/nodejs/met_server_listen.asp
반응형