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
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.