'TypeError: is not a function' in Node.js

前端 未结 8 1832
礼貌的吻别
礼貌的吻别 2021-02-03 16:48

I\'m getting the error while running the following code in Node.js

var assert = require(\'assert\');
var request = require(\'request\');
var index = require(\'./         


        
8条回答
  •  一向
    一向 (楼主)
    2021-02-03 17:23

    If you need to expose a specific component, function or a variable to public. You have to exports those components using JavaScript modules.

    let add = (a,b)=>{
        return ( a+b);
    }
    module.exports.add=add;
    

    or if you want to expose multiple functions, you can do as follows.

    let add = (a,b)=>{
        return (a+b);
    }
    let subtract = (a, b)=>{
        return (a-b);
    }
    module.exports={
       add : add,
       subtract : subtract
    };
    

提交回复
热议问题