Node.js 함수

黄舟
黄舟원래의
2017-01-17 15:54:031221검색

Node.js 함수

익명 함수:scope.js

[code]function execute(someFn, value) {
    someFn(value);
}
execute(function (word) {
    console.log(word)
}, 'hello');

Node.js 함수


함수 전달로 HTTP 서비스가 작동하는 방식

사례: server.js

[code]var http = require('http');
var onRequest = function (request, response) {
    response.writeHead(200, { "Content-Type" : "text/plain"});
    response.write("Hello world");
    response.end();
}
http.createServer(onRequest).listen(8888);
console.log('服务器监听端口 8888');

Node.js 함수

클라이언트: http://localhost:8888/%E5%87%BD%E6%95%B0/server.js

Node.js 함수

위는 Node.js 함수 내용입니다. 더 많은 관련 내용은 PHP 중국어 홈페이지(www.php.cn)를 참고해주세요!


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:Node.js 모듈 적용다음 기사:Node.js 모듈 적용