zoukankan      html  css  js  c++  java
  • NodeJS模块系统

    为了让NodeJS的文件可以相互调用,NodeJS提供了一个简单的模块系统。

    模块是NodeJS应用程序的基本组成部分,文件和模块是一一对应的,换言之,一个NodeJS文件就是一个模块,这个文件可能是javascript代码,JSON或者编译过的C/C++扩展。

    创建模块

    // hello.js

    exports.world = function(){

        console.log('hello world');

    }

    // main.js

    var hello = require('./hello');

    hello.world();

    require方法

    require方法接受以下集中参数的传递

    1、http、fs、path等,原生模块。

    2、./mod或./mod,相对路径的文件模块。

    3、/pathtomodule/mod,绝对路径的文件模块。

    4、mod,非原生模块的文件模块。

  • 相关阅读:
    HTML超链接应用场景
    String 字符串和StringBuffer的知识点总结
    猜数游戏代码
    MemoryLayout
    偏swift框架
    git的使用
    寄存器
    swift基础
    枚举
    安装Ubuntu 20.04 以后
  • 原文地址:https://www.cnblogs.com/yzpweber/p/6569176.html
Copyright © 2011-2022 走看看