How to Create a Javascript Console in Sublime Text
Method 1 of 2:
Using JSC (Mac OS X)
Setting Up
- Launch Sublime Text.
- JSC is a command-line Javascript runner, cooked directly into Mac OS X. Because most Macs already contains everything you need to run the script, creating the build system in Sublime Text is incredibly easy.
- If you have a Windows computer, see the directions for Node.js below.
- Go to Tools > Build System > New Build System in the top bar.
- Paste this code into the resulting new tab that Sublime Text opened. Replace anything else in it:
{ "cmd": ["/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc", "$file"], "selector": "source.js" }
- Save the file as JSC.sublime-build in the default "user" folder. Now you have created your build system!
Using the Console
- Open the Javascript file that you want to run in Sublime Text.
- Use debug() instead of console.log() in your script.
- Go to Tools > Build System in the top bar and select JSC. This is the build system that you just created.
- Build the Javascript file. Use either the shortcut (Ctrl+B for Windows, and ⌘ Cmd+B for Mac), or choose Build from the Tools menu. A console will now appear in a pane at the bottom of the window, showing the results of your script!
Method 2 of 2:
Using Node.js
Setting Up
- Download the Node installer from the project's homepage and run it. Simply use the default settings.
- Node.js (Node) is a platform built to allow Javascript to run on a server. However, it can also be installed on your local computer, providing a relatively simple way to run Javascript and get the results without using a browser.
- Go to Tools > Build System > New Build System in the top bar.
- Paste this code into the resulting new tab that Sublime Text opened. Replace anything else in it:
{ "cmd": ["node", "$file"], "selector": "source.js" }
- If you receive a "[Errno 2]" error, then you'll need to change node in the code above to the path where node is located. To do this, open terminal and run which node. This will print out the path to the node binary.
- Save the file as node.sublime-build in the default "user" folder. Now you have created your build system!
Using the Console
- Open the Javascript file that you want to run in Sublime Text.
- Go to Tools > Build System in the top bar and select node. This is the build system that you just created.
- Build the Javascript file. Use either the build shortcut (Ctrl+B for Windows, and ⌘ Cmd+B for Mac), or choose Build from the Tools menu. A console will now appear in a pane at the bottom of the window, showing the results of your script!
4 ★ | 22 Vote
You should read it
May be interested
- How to Enable Webglthis tipsmake teaches you how to enable webgl. webgl (web graphics library) is a javascript api that is used to render 2d and 3d graphics within a compatible web browser. open google chrome . it has an icon that resembles a red, yellow, and...
- How to Use JavaScript Injectionsjavascript injection is a process by which we can insert and use our own javascript code in a page, either by entering the code into the address bar, or by finding an xss vulnerability in a website. note that the changes can only be seen...
- How to Enable JavaScriptthis wikihow teaches you how to turn on your computer browser's javascript, which allows your browser to load and view certain elements--such as videos or animations--on some web pages. you can enable javascript using chrome on desktop and...
- How to Disable JavaScriptthis wikihow teaches you how to turn off your web browser's javascript support. javascript is responsible for loading dynamic content in webpages, so turning it off can help websites load faster than usual. most web browsers and their...
- How to Set the Path in Javathis wikihow teaches you how to set the path for your java installation on windows, macos, and linux. if you're using a windows pc or mac and have just installed java, there's typically no need to do this manually as the path is set during...
- How to Get Input from Console in Javato start with, you need to determine the operating system that is being used. to begin with, you have to launch the control panel. the command to launch the same varies in the windows based operating system and the mac based operating...