Example

 

const os = require('os')
const path = require('path')
const {format} = require('date-fns')



console.log(os.type())
console.log(os.version())
console.log(os.homedir())

console.log(__dirname)
console.log(__filename)

console.log(path.dirname(__filename))
console.log(path.basename(__filename))
console.log(path.extname(__filename))
console.log(path.parse(__filename))

console.log(format(new Date(), 'yyyyMMdd\tHH:mm:ss'))

const fs = require('fs')

// Note: path.join inserts the slash. The slash is different on different Operating systems.
fs.readFile(path.join(__dirname, 'files', 'starter.txt'), 'utf8',  (err, data) => {
  if (err) throw err
  console.log(data.toString())
})

fs.writeFile(path.join(__dirname, 'files', 'temp.txt'), 'foobar', (err) => {
  if (err) throw(err)
  console.log('write complete')
})

process.on('uncaughtException', err => {
  console.error(`There was an uncaught error ${err}`)
  process.exit(1)
})