What is this Javascript “require”?

前端 未结 7 863
心在旅途
心在旅途 2020-11-22 03:46

I\'m trying to get Javascript to read/write to a PostgreSQL database. I found this project on github. I was able to get the following sample code to run in node.

<         


        
7条回答
  •  你的背包
    2020-11-22 04:20

    So what is this "require?"

    require() is not part of the standard JavaScript API. But in Node.js, it's a built-in function with a special purpose: to load modules.

    Modules are a way to split an application into separate files instead of having all of your application in one file. This concept is also present in other languages with minor differences in syntax and behavior, like C's include, Python's import, and so on.

    One big difference between Node.js modules and browser JavaScript is how one script's code is accessed from another script's code.

    • In browser JavaScript, scripts are added via the

提交回复
热议问题