Skip to content

Latest commit

 

History

History
57 lines (44 loc) · 820 Bytes

File metadata and controls

57 lines (44 loc) · 820 Bytes

Cheat Sheet

CommonJs import/export style

export

module.exports = {
  alias: functionName,
  //OR, Directly and PREFERED
  functionName,
}

import

const db = require("../assignment1/db")
//then use
db.functionName()

ES6 import/export style

💡 First of all, you have to add this property to the nearest package.json

{
  "type": "module"
}

export

export function functionName() {
  //body
}

import

import { functionName, secondFunctionName } from "moduleName"

To write PrettyPrinted JSON to a file

fs.writeFileSync(FILE_PATH, JSON.stringify([], null, 2))

To generate random string(commonly used as TOKEN_KEY for jwt authentication)

require('crypto').randomBytes(64).toString('hex)