This file and the introduction of functions from other modules;
Introduced from other modules only supports the introduction of a function and several of these two
Cases:
Test.js main function
varHttp=require (' http '); Http.createserver (function(request,response) {Response.writehead (200,{' content-type ': ' text/html '}) func1 (response);//Call InternalOTHERFUN.FUNC3 (response);//Calling external functionsConsole.log (' Access '); Response.End ("Hello,world\n");}). Listen (8887); Console.log (' Server runing at http://127.0.0.1:8887 ');//calling an external function requires the introduction ofvarOtherfun = require ("./moudel/asfunc.js");varfunc1=function(res) {Console.log ("Func1"); Res.write ("Hello,woshi func1");};
Asfunc.js
//supports multiple functionsModule.exports ={func2:function(res) {Console.log ("Func2"); Res.write ("Func2,,,"); }, Func3:function(res) {Console.log ("Func3"); Res.write ("Func3,,,"); }}//var func2 = function (res) {//Console.log ("Func2");//res.write ("Func2,,,");// }//module.exports = FUNC2;//supports a function
Execution results
node. JS Learning notes Call function