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
반응형
'서버(Server) > Server&Nodejs&DB' 카테고리의 다른 글
JWT token 구조 및 생성 (0) | 2018.08.17 |
---|---|
MYSQL 외래키(Foreign key) 지정(RESTRICT, CASCADE, NO ACTION, SET NULL) (0) | 2018.08.15 |
라우터와 미들웨어 use (0) | 2018.07.23 |
[Nodejs] fs (파일 시스템) 읽기, 쓰기, 붙여쓰기, 삭제 등등.. (0) | 2018.07.23 |
PM2_프로세스 관리 도구 (0) | 2018.07.09 |