Skip to content

Tips

Handy tips always at your fingertips

A collection of 123 tips that come in real handy when you need them. Originally posted as tweets on my Twitter account, and now gathered here so you can browse them easily.

Mapping of HTTP Status Messages in Node.js

πŸ’‘ Want to send a message along with an HTTP status code response?

πŸ‘‰πŸΌ @nodejs has a built-in mapping of HTTP status codes and their respective messages.

The STATUS_CODES (uppercase) object of the http module has a mapping of status code to status message (e.g. STATUS_CODES[404]). Node.js mapping of status codes and their corresponding message. Read tip

Large Node.js Project Example to Learn From

πŸ’‘ What's a good example of a mid/large Node.js open-source project to learn from?

πŸ‘‰πŸΌ I recently found out that Send from the folks at @mozilla is written in Node.js and it's open-source!

https://github.com/mozilla/send

Read tip

Disable NPM Update Notifications

πŸ’‘Want to get rid of NPM update notifications?

➑️ npm config set update-notifier false

A wild NPM update notification in the terminal has appeared. Read tip

Test Your Regex in a Playground

πŸ’‘ Many folks trip over the Regex syntax. Writing a working regular expression involves many trials & errors.

πŸ‘‰πŸΌ I always prefer writing #regex in playgrounds so I can immediately test them, of which @regex101 is my favourite.

https://regex101.com/

Read tip

Tiny JSON DB for Quick Prototyping

πŸ’‘ A JSON file is the simplest form of storage and a quick way to start your next project.

πŸ‘‰πŸΌ lowdb by @typicode is built on top of lodash offering a familiar API. Ideal for quick prototypes and CLIs.

https://github.com/typicode/lowdb

Read tip

Generate Secure and Clean Unique IDs

πŸ’‘ Need to generate unique IDs that will be shown to users? Don't like the awkwardly long MongoDB IDs?

πŸ‘‰πŸΌ nanoid by @sitnikcode does just that. This super tiny lib (0.008kb!) is secure and has a low collision %.

https://github.com/ai/nanoid

Read tip

Organise Large Nginx Configs

πŸ’‘ Nginx configuration files can quickly become long and difficult to maintain.

πŸ‘‰πŸΌ Break up configuration into standalone units and place them in /etc/nginx/snippets. Use the "include" directive to import them.

Typical Nginx configuration using two includes to import configurations from snippets/security.conf and snippets/general.conf. Read tip

Difference Between Apt and Apt-Get

πŸ’‘ You might have read some articles using apt and others apt-get. What's the difference?

πŸ‘‰πŸΌ apt is a newer and higher level API that combines commonly used commands from apt-get and apt-cache. It's more user-friendly and the recommended tool to use.

Read tip

Quickly Test Glob Patterns

πŸ’‘ Always fiddling and guessing glob patterns like I do? Never truly grasping the syntax.

πŸ‘‰πŸΌ Glob tool by @digitalocean lets you quickly test globs against sets of strings. It even has examples for commonly used glob patterns.

https://www.digitalocean.com/community/tools/glob

Read tip