How to include nodejs modules in html files?

后端 未结 3 685
误落风尘
误落风尘 2021-02-05 11:36

First of all I am new to nodejs and secondly below is my question. How to include nodejs net module in js which is loaded in html??

My js file looks like this.



        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-05 11:51

    The reason "require is not defined" is because "require" is a keyword of node.js, but it is not a keyword in browser.

    Node.js is a virtual machine (or running context) for javascript, browser is also a virtual machine for javascript. But they are hugely different. You cannot use a keyword supported in one virtual machine in another virtual machine, just like you can use C/C++ on both Windows and Linux, but there are many libraries that are either in Linux only or Windows only.

提交回复
热议问题