当前位置:网站首页>Nodejs file operation
Nodejs file operation
2022-04-22 18:45:00 【Xiao Er Li】
This article will introduce nodejs Some operations of reading and writing local files .
Reading documents
const fs = require('fs')
const path = require('path')
const fileName = path.resolve(__dirname, 'data.txt')
console.log(fileName)
// Reading documents
fs.readFile(fileName, (err, data) => {
if (err) {
console.log(err)
return
}
// data It's a binary type , Need to be converted to a string
console.log('readFile',data.toString())
})
Writing documents
const content = ' What to write '
const opt = {
flag:'a' // Append mode
}
fs.writeFile(fileName, content, opt, (err) => {
if (err) {
console.log(err)
}
})
Judge whether the file exists
fs.exists(fileName, (exist) => {
console.log('exits',exist)
})
版权声明
本文为[Xiao Er Li]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221841308876.html
边栏推荐
猜你喜欢

TypeScript中的命名空间使用
![[fundamentals of interface testing] Chapter 10 | explain the pre script of postman request and its working principle in detail](/img/b1/64d4996fb27939dfbd98a6f0da8671.png)
[fundamentals of interface testing] Chapter 10 | explain the pre script of postman request and its working principle in detail

【网络安全】Duomicms的变量覆盖漏洞从白盒测试到实战

花样机模板电脑CAD免费打板转格式软件PS300B使用步骤教程:日本兄弟牌Brother花样机通用CAD画图打板.dxf文件转.emb文件

运行npm install命令的时候会发生什么?

Pytoch Note58 CNN可视化

免外围电路ESP32/ESP8266系列单片机串口一键下载方案

Model Inspector — 软件模型静态规范检查工具

.net core 中使用IAsyncExceptionFilter 捕获全局异常,统一返回信息

大话测试数据(二):概念测试数据的获取
随机推荐
带你了解极具弹性的Spark架构的原理
【论文泛读】Easing Embedding Learning by Comprehensive Transcription of Heterogeneous Information Networks
2022语言与智能技术竞赛再升级,推出NLP四大前沿任务
fastjson的JSONObject数据保证顺序
【驱动】TX2移植EC20启动模块
学习编程过程中感觉很有趣,为什么到单独去做项目就不知道从何下手?
【接口测试基础】第九篇 | 详解PostMan全局变量和环境变量
TypeScript中的命名空间使用
Win10问题篇:一次性永久关闭win10系统自动更新
Recommendation of safe, fast and low-cost futures companies in 2022?
描述文件中的全局类型
C# 从list 或者string中随机获取一个
IM即时通讯开发如何设计能支撑百万并发的数据库
【全网最全】JSR303参数校验与全局异常处理(从理论到实践别用if判断参数了)
Hackmyvm (XXV) helium, series of articles continuously updated
MFC principle and method (II)
Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
Jsonobject data guarantee order of fastjson
如何设计 API 接口,实现统一格式返回
062 反序列化漏洞