Why are some NodeJS requires capitalized?

Hello, everybody!

I was researching the Koa framework and its examples because I was inspired by dolya.me, which @Zavexeon and @TheDrone7 made together. So here's my question:

Why are some requires capitalized? For example:

Take a look at this line:

Why is Koa capitalized?

Or this:

Why isn't ejs capitalized?

Or this:

Why is Router capitalized, but phin isn't, but FieldValue is?

I'm scratching my head right now.

Thanks for reading,

P.S. Why am I asking? For the sake of consistency, of course!

You are viewing a single comment. View All


the npm package koa exports a default function object. you assign that to a variable called Koa with the const variable declaration using nodes global commonjs require method. Koa is capitalized because the value assigned to it is a constructor function, and you can create instances of it (i.e. app) by using the new keyword

in other words. with koa's api, you are able to do this

just like if you create a class

you can instantiate an instance of it, like you do with koa (but app instead of myDog)

in java, you may do this (i'm a bit rusty)

Scanner, Dog, and Koa are all capitalized because they are constructors and you can create instances of it with the new keyword

so we can reason that it doesn't make much sense do this

because ejs and uid are lowercase. you probably wont find new ejs() in their documentation simply because they are not constructors, that is not how you are supposed to use the library

without using firebase-admin some people would resonably infer that one way to use it is by writing a new FieldValue() somewhere, simply because its capitalized in that way

so in short, it is a convention to capitalize in that manner. and that usually correlates with how you would use the library. of courses, sometimes there are exceptions :P
nice question btw :)



By the way, Mr Drone himself told me that he capitalized the things because he just looked at the documentation on Github and copied that. But thanks for the answer!


@MatthewDoan1 yah! glad i could help :)


@MatthewDoan1 To elaborate a bit, constructor functions are also known as "classes".