Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run JavaScript in Sublime Text

Tags:

javascript

I have searched and found a way to make JavaScript works on SublimeText. The way is like that in steps:

  • Sublime Text > File > New File > Type: console.log("Hello World");
  • Press Ctrl + S (Save) > script.js
  • Install Node.js

  • Sublime Text > Tools > Build System > New Build System > Type:

    {
    	"cmd": ["node", "$file"],
    	"selector": "source.js"
    }
  • Save As Node.sublime-build
  • Sublime Text > Tools > Build System > Node

That worked well and I can get the console results well Now how can I use or refer to the index.html file? To be more specific I have two files: index.html and script.js and I need to run the JS on sublime text but I got ReferenceError: document is not defined on such a line

var output = document.getElementById('output');
like image 334
YasserKhalil Avatar asked Jul 03 '26 18:07

YasserKhalil


1 Answers

document object. relates to the DOM(Document Object Model) in the Web Browsers. Node.js is desktop JavaScript runtime environment, It'll not give to access to DOM objects.

If you want to access the document, object in Node.js you can use browserify

like image 59
Anurag Yadav Avatar answered Jul 05 '26 07:07

Anurag Yadav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!