当前位置:网站首页>fs. Readfile() and fs writeFile()
fs. Readfile() and fs writeFile()
2022-06-21 17:30:00 【Yu'an_ ZhangDe】
Installation configuration NodeJs Environmental Science
Want to use these two methods , First you need to install the configuration NodeJs Environmental Science , I put the link here , Please go to the rookie tutorial to see the specific tutorial , I won't go into details here .
Node.js Installation configuration | Novice tutorial (runoob.com)
fs.readFile()
fs.readFile() Method , Used to read the contents of the specified file
Usage method
// Import fs modular
const fs = require('fs') // amount to <script src='./fs></script>
// 2、fs.readFile(' Path to file ',' Coding format ', Callback function )
// fs.readFile('./test1.js','utf8',(err,data)=>{
fs.readFile('./test.js', 'utf8', (err, data) => {
// Read successful err by null
// Read failed err For the wrong person
if (err) return console.log(err.message);
console.log('==========');
console.log(data);
})test.js
console.log('node');
let a = 1
let b = 2
console.log('--------------------------');
console.log(a + b); //3Use... On the terminal node Execute this document

fs.writeFile()
fs.writeFile() Method , Used to write content to the specified file
Usage method
const fs = require('fs')
fs.writeFile('./test.js','Hello world',err => {
if(err) return console.log(err);
console.log('===============');
console.log(' Write successfully ');
})test.js
console.log('node');
let a = 1
let b = 2
console.log('--------------------------');
console.log(a + b); //3Use... On the terminal node Execute this document
Be careful :fs.writeFile() Is to rewrite the contents of the target file , Will not add... From the original content
边栏推荐
猜你喜欢

函数调用模型

Three color mark removal method

Function call model

20 pygame模块制作一个跳跃的小球游戏

Beaucoup de sociétés de logiciels sont en fait des "blagues"

「运维有小邓」Active Directory批量修改用户

牛客网:验证IP地址
![[MySQL learning notes 18] constraints](/img/29/c72f83bfae8fd8b43e78cdf1aa9cbc.png)
[MySQL learning notes 18] constraints

Notice on the third national operation research / data, model and decision-making course teaching seminar in 2022

【mysql学习笔记15】用户管理
随机推荐
Use picgo core and Alibaba cloud to automatically upload typera pictures
How can aggressive programmers improve R & D efficiency Live broadcast Preview
一些细节
Function call model
Not this year's 618?
Kotlin DSL build
[issue 349] Interviewer: how to gracefully customize the ThreadPoolExecutor thread pool?
剑指 Offer II 089. 房屋偷盗 / 剑指 Offer II 090. 环形房屋偷盗
疫情数据对应的大陆和全球的矢量数据下载,基于geojson转shp
[Error] ‘vector‘ was not declared in this scope
用Node创建一个服务器
Move Protocol Beta测试版稳定,临时决定奖池规模再扩大
QT5知识:字符串列表QStringListModel
Template: p6114 [template] Lyndon Decomposition & runs (string)
Common formula of derivative__ Common formulas of indefinite integral
path.join() 、path.basename() 和 path.extname()
Qt5 knowledge: string list qstringlistmodel
gp中的decode函数实现
NLog自定义Target之MQTT
高精度压位模板
