Home  >  Article  >  Web Front-end  >  Node.js functions

Node.js functions

黄舟
黄舟Original
2017-01-17 15:54:031150browse

Node.js function

Anonymous function: scope.js

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

Node.js functions


How function passing makes the HTTP service work

Case: 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 functions

Client: http://localhost:8888/%E5%87%BD%E6%95%B0/server. js

Node.js functions

#The above is the content of the Node.js function. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn