Home > Net >  Why do JavaScript filenames sometimes have dots?
Why do JavaScript filenames sometimes have dots?

Time:04-14

I have the following question and is it because there are javascript file names with dots?

For example:

In a node js project with express, I found the following files:

user.route.js

user.controller.js

CodePudding user response:

Because it very clearly when you read the filename, you can know the responsibility of file, object is handling, Business model of project. Easy maintain, fix bug.

CodePudding user response:

It is the same reason why you put files in different directories. Why would we do that? We want to organize the files in a manageable manner. So, we put routing related files in routes directory, business logic related files in service directory.

Another way of organizing files is to have the type of the file mentioned in the name itself. The file name user.route.js says, it contains routes related to user. The file user.controller.js says, it contains controller functions related to user.

If you think more about it, it is similar to having extensions in file names. Files ends with .js tells us, it is a JavaScript file. Same goes for .css, .html, etc files. The same way, files ends with .route.js tells us, it is a file that has routing related JavaScript code. So, what does files that ends with .controller.js tells you?

  • Related