admin管理员组文章数量:1431037
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');
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');
- 5 No, there is not. You cannot run PHP or on the client side either. – Bergi Commented Jun 5, 2018 at 20:50
- node.js runs on the server, not the client. – Barmar Commented Jun 5, 2018 at 20:50
-
Of course, many of the modules from npm work in the browser as well, you might have to use a module bundler that supports monjs
require
though – Bergi Commented Jun 5, 2018 at 20:51 - Possible duplicate of JavaScript require() on client side – Wayrex Commented Jun 5, 2018 at 20:51
- You need to tell us what your end goal is. Building websites with node (express) requires you to use templates and the like, and switching to that from PHP can be challenging. Plus, you obviously won't be able to run arbitrary node code in a browser environment anyway, given the restrictions on, say, file access and the like. Is this about a specific module? Or just about having to trouble to wrap your head around templating? – user5734311 Commented Jun 5, 2018 at 21:00
1 Answer
Reset to default 4From 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/
本文标签: javascriptIs there any way to run Nodejs in a ltscriptgt tagStack Overflow
版权声明:本文标题:javascript - Is there any way to run Node.js in a <script> tag? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745524210a2661761.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论