Executing a JavaScript file directly from the browser

前端 未结 6 1113
攒了一身酷
攒了一身酷 2021-01-31 04:31

This sounds like a trivia question but I really need to know.

If you put the URL of an HTML file in the Location bar of your browser, it will render that HTML. That\'s

6条回答
  •  臣服心动
    2021-01-31 05:09

    Use Node.js. Download and install node.js and create a http/s server and write down what you want to display in browser. use localhost::portNumber on server as url to run your file. refer to node js doc - https://nodejs.org/dist/latest-v7.x/docs/api/http.html

    Run - http://localhost:3000

    sample code below :

      var http = require("http");
      var server = http.createServer(function(req,res){
      res.writeHead(200,{'Content-Type':'text/html'});
           res.end("hello user");
      }); server.listen(3000);`
    

提交回复
热议问题