node. JS Learning notes Call function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.