nodejs

73 阅读1分钟

fs模块

const files = fs.readdirSync(this.dir, { withFileTypes: true }) // 读取文件夹里文件类型
files = files
      .map((file) => (file.isFile() ? file.name : null))
      .filter((item) => item) //找出文件夹的文件
fs.readFileSync(codeFilePath, 'utf-8')      //读取文件
fs.mkdirSync(this.targetPath, { recursive: true }) // recursive:没有就创建
      

child_process模块

const { execSync } = require('child_process')
const buffer = execSync(`python3 ${pythonShellPath} a b c`) // 执行shell命令

os模块

const homedir = os.homedir() //用户主目录

url

import { fileURLToPath } from 'node:url'
const __dirname = fileURLToPath(new URL('.', import.meta.url))