博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
node.js删除文件_如何使用Node.js删除文件
阅读量:2508 次
发布时间:2019-05-11

本文共 1020 字,大约阅读时间需要 3 分钟。

node.js删除文件

How do you remove a file from the filesytem using Node.js?

如何使用Node.js从文件系统中删除文件?

Node offers a synchronous method, and an asynchronous method through the fs built-in module.

Node通过fs内置模块提供同步方法和异步方法。

The asynchronous one is fs.unlink().

异步的是fs.unlink()

The synchronous one is fs.unlinkSync().

同步的是fs.unlinkSync()

The difference is simple: the synchronous call will cause your code to block and wait until the file has been removed. The asynchronous one will not block your code, and will call a callback function once the file has been deleted.

区别很简单:同步调用将导致您的代码阻塞并等待,直到文件被删除。 异步代码不会阻塞您的代码,并且在删除文件后将调用回调函数。

Here’s how to use those 2 functions:

这是使用这两个功能的方法:

fs.unlinkSync():

fs.unlinkSync()

const fs = require('fs')const path = './file.txt'try {  fs.unlinkSync(path)  //file removed} catch(err) {  console.error(err)}

fs.unlink():

fs.unlink()

const fs = require('fs')const path = './file.txt'fs.unlink(path, (err) => {  if (err) {    console.error(err)    return  }  //file removed})

翻译自:

node.js删除文件

转载地址:http://eoqgb.baihongyu.com/

你可能感兴趣的文章
在VIM中使用GDB调试 – 使用vimgdb
查看>>
python爬虫---从零开始(五)pyQuery库
查看>>
POJ2236(KB5-A)
查看>>
Centos MySQL数据库迁移详细步骤
查看>>
2初出茅庐--初级篇2.1
查看>>
新建 WinCE7.0 下的 Silverlight 工程
查看>>
腾讯的张小龙是一个怎样的人?
查看>>
jxl写入excel实现数据导出功能
查看>>
linux文件目录类命令|--cp指令
查看>>
.net MVC 404错误解决方法
查看>>
linux系统目录结构
查看>>
git
查看>>
btn按钮之间事件相互调用
查看>>
Entity Framework 4.3.1 级联删除
查看>>
codevs 1163:访问艺术馆
查看>>
冲刺Noip2017模拟赛3 解题报告——五十岚芒果酱
查看>>
并查集
查看>>
sessionStorage
查看>>
代码示例_进程
查看>>
Java中关键词之this,super的使用
查看>>