-g is the global install flag, as explained in this answer. It’s covered in detail in this node blog post.
The rules of thumb:
- Install globally if the package provides command-line tools
- Install locally if you’re using the package as part of your application
- Install globally and locally if both use-cases apply