Skip to content

Instantly share code, notes, and snippets.

@LinZap
Created June 11, 2019 01:02
Show Gist options
  • Select an option

  • Save LinZap/7b8fe6f3e13dd3fe4689353dbf19f541 to your computer and use it in GitHub Desktop.

Select an option

Save LinZap/7b8fe6f3e13dd3fe4689353dbf19f541 to your computer and use it in GitHub Desktop.
Node.js - HK10
const fs = require('fs')
let dir_path = __dirname + '/storage'
let file_path = dir_path + '/hello.txt'
let str = 'Hello world'
if (!fs.existsSync(dir_path))
fs.mkdirSync(dir_path)
if (fs.existsSync(file_path))
fs.appendFileSync(file_path, str)
else
fs.writeFileSync(file_path, str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment