How to execute a JavaScript file on local machine? - Stack Overflow

I am having issues getting my JavaScript to run on my local machine and I am not using Node.js, I am lo

I am having issues getting my JavaScript to run on my local machine and I am not using Node.js, I am looking for a way to run the JavaScript code with setting up a VM with a webserver etc. But if that is needed I will. Is it possible to run the JavaScript file without a webserver?

I am having issues getting my JavaScript to run on my local machine and I am not using Node.js, I am looking for a way to run the JavaScript code with setting up a VM with a webserver etc. But if that is needed I will. Is it possible to run the JavaScript file without a webserver?

Share Improve this question edited Apr 17, 2018 at 3:28 NightOwl888 57k28 gold badges147 silver badges220 bronze badges asked Apr 17, 2018 at 3:22 Christian SoljeChristian Solje 231 gold badge2 silver badges4 bronze badges 6
  • save .js file, open HTML file that includes that .js file – CertainPerformance Commented Apr 17, 2018 at 3:24
  • 1 You can run it in a web browser, just use an html that has an import to the script you're using. You can view execution in the browser console. – Joe Thomas Commented Apr 17, 2018 at 3:24
  • chrome / in browser... – Denis Tsoi Commented Apr 17, 2018 at 3:24
  • In addition to running it in chrome/browser, if you install node, you can just run the js file from the mand line with node filename.js. You don't need to run node as a web server. – Josh F Commented Apr 17, 2018 at 3:26
  • There is post on SuperUser that might help: Is there a way to run Javascript without a browser, like a shell or batch script?. – Gino Mempin Commented Apr 17, 2018 at 3:27
 |  Show 1 more ment

1 Answer 1

Reset to default 1

You can run it directly into a HTML file.

For that, create a simple html page, like the example below and put your script into tags.

<!DOCTYPE html>
<html>
    <body>

        <h1>My First Heading</h1>
        <p>My first paragraph.</p>

        <script>
            alert('something'); // Js code goes here
        </script>

    </body>
</html>

Put this code into any text editor and save the file as .html extension, it can be runned on any modern web browser like Chrome, Firefox or IE/Edge.

Note that the tag pauses the page rendering till it ends the execution.

Also google jsfiddle if you need to run more plex codes.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745093792a4610852.html

相关推荐

  • How to execute a JavaScript file on local machine? - Stack Overflow

    I am having issues getting my JavaScript to run on my local machine and I am not using Node.js, I am lo

    14小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信