nodejs的第二个小程序
来源:互联网 发布:杠杆炒股盈利算法 编辑:程序博客网 时间:2024/05/30 20:09
var http = require('http');
var otherfun = require('./models/otherfuns.js');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
if(request.url!=="/favicon.ico"){ //清除第2此访问
otherfun.controller(request,response);
otherfun.call(response);
response.end('');
}
}).listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
//---普通函数
function fun1(res){
res.write("你好,我是fun1");
}
//-------------------models/otherfuns.js--------------------------
function controller(req,res){
//res.write("发送");
call('hello',req,res);
res.end("");
}
function call(res){
console.log('call');
}
module.exports = controller; //只支持一个函数
/*
//支持多个函数
module.exports={
getVisit:function(){
return visitnum++;
},
add:function(a,b){
return a+b;
}
}
*/
//-----------------用函数名的字符串调用------------------
var http = require('http');
var otherfun = require("./models/otherfuns.js");
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
if(request.url!=="/favicon.ico"){ //清除第2此访问
//fun1(response);
//-------用字符串调用对应的函数---
funname = 'fun3';
otherfun[funname](response);
//otherfun['fun3'](response);
response.end('');
}
}).listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
var otherfun = require('./models/otherfuns.js');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
if(request.url!=="/favicon.ico"){ //清除第2此访问
otherfun.controller(request,response);
otherfun.call(response);
response.end('');
}
}).listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
//---普通函数
function fun1(res){
res.write("你好,我是fun1");
}
//-------------------models/otherfuns.js--------------------------
function controller(req,res){
//res.write("发送");
call('hello',req,res);
res.end("");
}
function call(res){
console.log('call');
}
module.exports = controller; //只支持一个函数
/*
//支持多个函数
module.exports={
getVisit:function(){
return visitnum++;
},
add:function(a,b){
return a+b;
}
}
*/
//-----------------用函数名的字符串调用------------------
var http = require('http');
var otherfun = require("./models/otherfuns.js");
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
if(request.url!=="/favicon.ico"){ //清除第2此访问
//fun1(response);
//-------用字符串调用对应的函数---
funname = 'fun3';
otherfun[funname](response);
//otherfun['fun3'](response);
response.end('');
}
}).listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
0 0
- nodejs的第二个小程序
- nodejs的第一个小程序
- 轻轻敲开nodeJs的大门--第一个nodeJs入门小程序
- nodejs的第一个程序
- OpenGLES第二个小程序,旋转并上色的正方体
- 第二个类似的程序,也有点小问题
- 第二个小程序 十进制与十六进制的转换
- c++调用Python的第二个小程序
- 学习nodejs第二课,一个简单的nodejs程序
- 第二个vb小程序:迷你记事本
- 实习期间第二个小程序
- 基于Nodejs的第一个小爬虫
- nodejs的第一个程序Hello World
- 我的第一个NodeJS程序
- 我的第一个NodeJS WebSocket程序
- c++的 第二个程序
- 我们的第二个程序
- 设计的第二个程序
- Java泛型(二)——使用Gson解析复杂的泛型嵌套泛型数据结构
- 斯坦福大学卷积神经网络----Module 1 Lesson 1 图像分类
- Advice to professor Xin
- 如果有人问你 SQL 注入的资料,请叫他看这份速查表
- 关于在g++编译C++过程中调用移动构造函数
- nodejs的第二个小程序
- 图像是怎么转换为JPEG图像的
- 传统产业、传统企业为什么要进行互联网转型?
- HDU3450-Counting Sequences
- 排序算法总结(C++)
- poi导出excel例子
- ListView列表
- 打造CommonAdapter
- Java面向对象-Integer与int的区别