Is there any way to run Node.js in a <script> tag?

一曲冷凌霜 提交于 2021-01-28 14:27:19

问题


I would like to run Node.js in my webpage, the same way that you would with PHP or ASP.NET.

The reason for this is I would like to use require()'d modules from NPM in my browser javascript, however vanilla JS doesn't seem to support this. Is there any way I can run Node.js in my tags? If not, would requiring examplenodefile.js in my browser javascript work?

Edit: Is there any alternative to this, if it isn't possible? I know I can set script src but that doesn't really work as nicely as var foo = require('bar');


回答1:


From your above question I am assuming you want to use NPM modules in your browser side JavaScript. This is possible to do assuming you have web pack. You can use webpack to bundle the NPM packages inside a bundle file.

Check out webpack...

https://webpack.js.org/



来源:https://stackoverflow.com/questions/50708715/is-there-any-way-to-run-node-js-in-a-script-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!