The priority of require () 's parameter to determine the file-extension in nodejs

Viewed 103

I am learning node.js

for example, I try

var server = require("./myserver.js");  

and

var server = require("./myserver");  

Both of these two casework.

what if I have another file with the same name? e.g myserver.json, myserver.node , will it always search .js at first?

From one of the answerers in my previous question, he mentions only load the .json file if you explicitly add the .json extension to the require-call. So if you leave the extension, it always loads the .js file.

will this rule also suit to .node file?

2 Answers

Yes, If you will not provide the extension of the file, Then, it will first look at the JS file, since JS is by default

Related