简体   繁体   中英

Host html with javascript dependencies on node.js

My question is: Whether one can host an entire website along with JavaScript dependencies on node.js with/without express or other frameworks.

The JavaScript will contain html specific calls like using the window object to create a new window or post messages to other windows/web workers. I've had a bit of experience running JavaScript but have no experience running node and I've searched a lot trying to find a solid answer.

If this does require using a framework all I have to say is that this functionality should be already included in the vanilla node build from day 0 and why it is not confuses me.

Here is a basic HTML code example of what I want to run

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
let window = window.open()

 window.onload = function (){
  window.postmessage({hello:"world"})
  }
 </script>

 <script src="./ImageResource.js"></script>
 </body>
 </html>

Q/A

"Why not just open a page manually and communicate with it using node" I have a entire project built in vanilla JavaScript and do not wish to convert it to node compliant code (not yet).

Disclaimers: If you feel this question has been answered properly on another thread please instead of negative reviews I ask that you link it to me so I may question whether or not I should take down my thread for deprecation. Thank you have a nice day..

Yes, you can. Express and what not are all built in JavaScript after all.

But, why would you want to? Express isn't generally considered a heavyweight framework. It doesn't impose much on you, and it utilizes the underlying Node.js-built-in HTTP request/response objects. It's a good tool in general.

In any case, it doesn't sound like you need Node.js at all for your project. Any web server will do. Node.js is generally used for server-side work. It isn't needed to just host your web page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM