Home >Web Front-end >JS Tutorial >Node.js functions
Node.js function
Anonymous function: scope.js
[code]function execute(someFn, value) { someFn(value); } execute(function (word) { console.log(word) }, 'hello');
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');
Client: http://localhost:8888/%E5%87%BD%E6%95%B0/server. js
#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)!