aizatto.com
  • aizatto.com
  • Table of Contents
  • Portfolio, Projects, Tools, Toys
  • Interview Guide
    • Choosing A Company
    • Job Boards
    • Practice
    • Technical Interview Cheatsheet
    • Interview Process
      • Questions to Ask
      • Coding
      • Soft Skills
      • Rejection
      • Negotiation / Deciding
      • Accepting, Joining
    • FAQ
  • Engineering Code
    • Communication
    • Different Types of Coding
    • Commit Messages
    • Reviewing Code
      • Requesting Changes
    • Writing Code
      • Consistency
      • Writing for a code base of 1,000,000+ Lines
      • Write Code Knowing It Will Be Refactored
      • Naming
        • Versioning
        • Create Searchable Names
      • Commenting
        • Don't commit commented code
      • Make It Easy To Reproduce
      • Scripts
      • 80 character limit
      • Exit Early
      • Be careful of enum in switch statements
      • Be careful about chaining conditions
      • Be careful of chaining ternary operators
      • Write Code Knowing You Will be Blamed
      • Hacks
      • Bad Practices
      • Logs
      • Time
      • Other rules
    • Engineering Code
    • Engineering Data
    • Pipelines
    • Configuration Files
    • Site Reliability Engineering (SRE)
    • Best Engineers
  • Engineering Management
    • Hiring
    • New Reports
    • 1:1s
      • Calibration
      • Expectations
      • Mentorship / Learning / Growing
      • Task Management
      • Teams
    • Interviewing Candidates
    • Messenger Groups
    • Resources
  • Why GitBook?
  • Getting into Tech
    • Terminology
  • Personal Goals
  • Daily Drivers
  • Contacting Me
  • Notes
    • JavaScript
      • Array
      • Async & Await / Promises
      • Booleans
      • Collections
      • Cons/Dislikes
      • fetch
      • Map
      • Modules
      • Object
      • Regex
      • Set
      • Style Guides
      • Versions
    • Node.js
      • Best Practices
      • DraftJS
      • eslint
      • GraphQL
      • Relay
      • Hapi
      • Knex
      • Koa
      • TypeScript
      • Webservers
    • Technical Due Diligence
    • Archive
      • Amazon Echo Dot (3rd Gen) with clock
      • Apple
        • AirPods Pro
        • Apple Notes
        • Apple Watch Series 4
        • iPad Pro 11" 2018
        • MacBook Pro 15" 2017
        • macOS
      • Audible
      • Balance
        • Growth vs Contentment
        • Leading vs Following
        • Mindful vs Mindless
        • New vs Old
      • Bags
      • Bandwidth Requirements
      • B2B/B2C
      • Blockchain
      • Board Games
        • Bang
      • Broadway
      • Cheap, Good, Fast
      • CLI
        • git
        • ufw
        • xargs
      • Cloud Providers
        • GCP
      • Communication
        • Asking Questions / Making Requests
        • Making Edits
        • Synchronous vs Asynchronous
        • Change Management
        • Problem Definition
      • Company
        • All Hands
        • The Problematic CTO
        • Organizational Structure
      • Content Creation
      • COVID 19/Corona Virus
      • Coworking Spaces
      • Daily Routine
      • Dating
      • Displays / Monitors
      • DNS
      • Domain Registrars
      • Driving
      • eCommerce
      • Empire Building
      • Facebook for Developers
      • Fever
      • Fiverr
      • Flights
      • Gaming Tablet
      • GitHub
      • GTD
      • Go Lang
      • Headsets
      • Hiking
        • Chamang Waterfalls
        • Kanching Waterfalls
        • Kota Damansara Community Forest Reserve
        • Sungai Chilling
      • Home Device Calling
      • iCalendar
      • Keyboards
        • Ergodox Ez
      • Malaysia Insurance
      • Mental Health Malaysia
      • Multiroom Wireless Speaker System
      • Musicals
      • Mouse
      • Movies
      • Password Managers
      • Phabricator
      • Physical Health
        • Cardio
      • Podcasts
      • Programming Bootcamps
      • Property
      • Productivity
        • Note Taking
      • Redang
      • Relationships
      • Referral Codes
      • Remote Calls
      • Remote Work
        • Comparison
      • Road Trips
      • Ruby / Ruby on Rails
      • Scraping
      • Slack
      • Stripe
      • Singapore
      • UX
      • Venture Builder
      • Video Games
      • Virtual Personal Assistant
      • VPN
      • WebDAV / CalDAV
      • WebSocket
      • Withings
      • Xiaomi Roborock Mijia
      • Old Hardware
        • Netgear R7000P
      • Web Development
        • React
        • SSO Providers
      • Software Engineering
        • Software Architectures
          • Monolithic
          • Non-Monolithic
            • Microservice
            • FaaS (Functions as a Service) or Serverless
        • Repository Management
  • More on Notion
Powered by GitBook
On this page
  • When starting a new project
  • Lerna
  • Use JSON5 over JSON
  • Package Recommendations
  • commander: command-line arguments
  • dotenv
  • fs-extra

Was this helpful?

  1. Notes
  2. Node.js

Best Practices

PreviousNode.jsNextDraftJS

Last updated 5 years ago

Was this helpful?

When starting a new project

  • Use

  • Use typescript

  • Use eslint

  • Use prettier

  • Use jest

  • Use husky

    • Used to lint files

See

Lerna

npx lerna init
npx lerna bootstrap --npm-client=yarn --use-workspaces

Update lerna.json

lerna.json
{
  "npmClient": "yarn",
  "useWorkspaces": "true"
}

Install

yarn install

Update package.json

package.json
{
  "scripts": {
    "lint": "yarn run lerna run lint"
  },
  "workspaces": ["packages/*"]
}

package.json when creating a new package:

packages/new-package/package.json
{
  "name": "new-package",
  "private": true,
  "version": "0.0.0"
}

Package Management

Each package manages it's own typescript and eslint.

For example, at the root directory.

yarn lerna run lint

Use JSON5 over JSON

yarn add json5

JSON5 Short Example:

{
  // comments
  unquoted: 'and you can quote me on that',
  singleQuotes: 'I can use "double quotes" here',
  lineBreaks: "Look, Mom! \
No \\n's!",
  newLine: "1\n\
2\n\
3",
  hexadecimal: 0xdecaf,
  leadingDecimalPoint: .8675309, andTrailing: 8675309.,
  positiveSign: +1,
  trailingComma: 'in objects', andIn: ['arrays',],
  "backwardsCompatible": "with JSON",
}

Package Recommendations

commander: command-line arguments

  • Used by create-react-app

yarn add commander

dotenv

  • Used by create-react-app

yarn add dotenv

As early as possible:

JavaScript:

require('dotenv').config()

TypeScript:

ts-node -r dotenv/config scripts/test.sh

Or

import { config: dotenv } from "dotenv"
dotenv();

fs-extra

  • Used by create-react-app

yarn add fs-extra

The JSON5 Data Interchange Format (JSON5) is a superset of that aims to alleviate some of the limitations of JSON by expanding its syntax to include some productions from .

fs-extra adds file system methods that aren't included in the native fs module and adds promise support to the fs methods. It also uses to prevent EMFILEerrors. It should be a drop in replacement for fs.

Lerna
https://github.com/aizatto/javascript-repository-template/blob/master/repositories.json
https://github.com/lerna/lerna
JSON
ECMAScript 5.1
https://json5.org/
https://github.com/json5/json5
https://www.npmjs.com/package/json5
https://www.npmjs.com/package/commander
https://github.com/motdotla/dotenv
graceful-fs
https://www.npmjs.com/package/fs-extra