module/tool.js
function formatApi(api){
return "http://www.shixiaobin.com/"+api
}
exports.formatApi=formatApi;
app.js
//引入http模块
const http=require('http');
const tools=require('./module/tools.js');
console.log(tools);
http.createServer(function (req,res) {
//req 获取客户端传过来的信息
//res 给浏览器响应信息
console.log(req.url);//获取url
//设置响应头
//状态码是200,文件类型是html,字符集是utf-8
res.writeHead(200,{"Content-type":"text/html;charset='utf-8'"}); //解决乱码
res.write("<head><meta charset='UTF-8'></head>"); //如果没有这一行,下面的 "你好" 是乱码 //解决乱码
res.write('this is nodejs');
res.write('你好 nodejs<br>');
var api=tools.formatApi('api/focus');
res.write(api);
res.end();//结束响应,如果没有这一行,浏览器左上角的图标一直在转圈
}).listen(3000); //端口建议3000以上,防止冲突