node.js中的函数调用

 时间:2024-11-04 14:13:40

1、结构目录图片

node.js中的函数调用

2、内容一:

node.js中的函数调用
node.js中的函数调用

3、内容2:这个没什么用,就不写了

4、内容三:var other = require("./otherfun.js"); //调入其他模块并赋予一个变量

node.js中的函数调用

5、内容4:这是otherfun.js的内容module.exports={ //外部调用必须写在这个里面fun2: function(res){res.write("你好,我是fun2");}, //注意,这个逗号很重要fun3: function(res){res.write("你好,我是fun3");}}

node.js中的函数调用

6、内容5:var http = require('http')挢旗扦渌;var other = require(&鳎溻趄酃quot;./otherfun.js"); //调入其他模块并赋予一个变量http.createServer(function(req,res){res.writeHead(200,{'Content-Type':'text/html;charset = UTF-8'}); //这是协议头,表示服务器回馈一个html网页if(req.url != '/favicon.ico'){ //清除两次访问的问题other.fun2(res);other.fun3(res);res.end('');} //这是协议尾,表示这个网页结束,如果没有会导致网页一直在加载}).listen(8000);console.log('server running in 127.0.0.1:8000');

node.js中的函数调用
node.js中的函数调用

7、内容6:var http = require('http')挢旗扦渌;var other = require(&鳎溻趄酃quot;./otherfun.js"); //调入其他模块并赋予一个变量http.createServer(function(req,res){res.writeHead(200,{'Content-Type':'text/html;charset = UTF-8'}); //这是协议头,表示服务器回馈一个html网页if(req.url != '/favicon.ico'){ //清除两次访问的问题var funName ="fun2";other['fun3'](res);other[funName](res);res.end('');} //这是协议尾,表示这个网页结束,如果没有会导致网页一直在加载}).listen(8000);console.log('server running in 127.0.0.1:8000');如果看起来不友好,请复制到js中打开

node.js中的函数调用
node.js中的函数调用
  • node.js的安装方法
  • 安装Node.js教程
  • CentOS如何安装Node.js?
  • Node.js的Async和Await函数
  • Node.js如何下载并安装
  • 热门搜索
    手抄报怎么做 我爱校园手抄报 体育手抄报图片 书香校园手抄报资料 关于健康的手抄报内容 关于迎新年的手抄报 我健康我快乐的手抄报 数学手抄报三年级下册 小学生科技手抄报图片 呵护心灵手抄报资料