Node JS之模块引入
来源:互联网 发布:艾瑞数据网 编辑:程序博客网 时间:2024/04/28 03:32
项目:Node.js_文件搜索模块
在main.js模块中调用searchMethod.js模块中的searchFiles(url)方法
实现给定一个URL,输出该URL下的所有文件(包括子文件)名称功能
//main.js文件const search = require('./searchMethod');search.world();// console.log(module);// console.log(fs);var url = "F:\\BaiduYunDownload\\lesson02"+ "\\node_lesson02\\nodelesson02";//调用子模块搜索方法 search.searchFiles(url);
//searchMethod.js文件const path = require('path');const fs = require('fs');exports.world = function(){ console.log("hello World!");}//搜索文件函数function searchFiles(url){ fs.readdir(url,function(err,files){ if(err) throw err; //循环读取文件 files.forEach(function(file){ let childPath = path.join(url,file); fs.stat(childPath,(err,stats) =>{ //判断是否文件 if(stats.isFile()){ console.log(childPath+"(files...)"); } //判断是否目录 if(stats.isDirectory()){ console.log(childPath+"(Directory...)"); searchFiles(childPath); } }); }); });}exports.searchFiles = searchFiles;
阅读全文
0 0
- Node JS之模块引入
- Node.js模块引入
- node.js之模块
- node.js模块之events
- Node.js之------模块篇
- node.js模块之exports
- Node.js之模块系统
- node.js学习教程之三:模块
- Node.js之模块的基本概念
- Node.js之缓冲模块Buffer
- Node.js第三方模块之download
- Node.js第三方模块之htmlparser2
- Node.js笔记之模块机制
- Node.JS核心模块之module分析
- node.js之基本文件系统模块fs
- node.js之基本http处理模块
- node.js之基础加密算法模块crypto
- Node.js模块小记之--util
- myeclipse
- 递归 放苹果问题和整数划分问题
- 精通比特币-第8章 挖矿与共识
- 如何在windows系统上运行linux命令
- shell 一列变一行
- Node JS之模块引入
- 精通比特币-第9章 竞争币、竞争块链和应用程序
- 关于registry key 'Software\JavaSoft\Java Runtime Environment' has value'1.8',but '1.7' is requaired问题
- Swing编程——快捷键设置方法的优劣对比(二)
- Hibernate使用Gson时报错:org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter?
- 精通比特币-第10章 比特币安全
- spring事务 connection
- MySQL 高级查询
- 30. Substring with Concatenation of All Words