I have searched and found a way to make JavaScript works on SublimeText. The way is like that in steps:
Install Node.js
Sublime Text > Tools > Build System > New Build System > Type:
{
"cmd": ["node", "$file"],
"selector": "source.js"
}
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');
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With