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
- JavaScript code to create bubble chart with custom markerthe example below shows a bubble chart with a customized highlight style and javascript source code that you can edit in your browser or save to your device to run locally.
- What is JavaScript? Can the Internet exist without JavaScript?not everyone knows what javascript is and how it works. the long and fascinating development history of javascript as well as what we can do with javascript is still unknown.
- How to Build Lorem Ipsum Text Generator Using JavaScript and Vitein this article, let's learn how to build a flexible lorem ipsum generator using vite and javascript. from there, you will improve your programming skills over time.
- Introduction to 2D Array - 2-dimensional array in JavaScriptin the following article, we will introduce and show you some basic operations to create and access 2-dimensional arrays - 2d array in javascript. essentially, a 2-dimensional array is a concept of a matrix of matrices - a matrix, used to store information. each 1 element contains 2 separate indexes: row (y) - column and column (x) - column.
- What is Currying in Javascript? How to use Currying in JavaScriptthe currying feature in javascript can help you keep your code tidy and give you a new way of seeing how functions work. currying is ideal when you want to break complex logic into smaller, manageable, and self-contained pieces of code.
- Things to know about 'this' in JavaScriptare you having trouble understanding the keyword 'this' in javascript ? then please read what you need to know about 'this' in javascript below.
- Udemy's top 5 JavaScript coursesa programming language that runs on any computer in the world. a language does not need any special software to run. a language ranked among the top in the world.
- Image Map in JavaScriptyou can use javascript to create image map at client-side. image maps are activated by the usemap attribute for the tag and are defined by special extension tags and.
- JavaScript code to create Pareto charts & graphsthe example below illustrates a pareto chart template created with javascript. you will also have the source code to edit in the browser or save to your computer to run locally.
- Top site with many good JavaScript exercises to practicemany people, after taking javascript courses and being equipped with some knowledge of the language they pursue, are eager to improve and cultivate these learned skills. so this article will give you a list of the top 3 websites to actually make javascript.