分为3步

1

先创建一个js文件,写入相关模块信息(方法、变量)

2

将模块进行导出操作

3

在新的js文件require之前创建的模块文件

  • 例如

    • 创建1.js

    let  name ={
      sayhello(){
          console.log("你好")
      }
    }
    ***导出操作****
    module.exports=name
    • 再创建2.js

    let Module=require('./1')
    console.log(Module)
    Module.sayhello()
    • 在终端输入

    node D:\Goworkspace\src\nodejs\2.js

    输出为:

node如何创建自定义模块

 

相关文章:

  • 2021-11-26
  • 2021-12-29
  • 2021-12-27
  • 2021-11-24
  • 2021-09-08
  • 2021-11-04
  • 2021-08-19
猜你喜欢
  • 2021-08-21
  • 2022-12-23
  • 2021-11-09
  • 2021-05-25
  • 2021-10-13
  • 2021-07-24
相关资源
相似解决方案