Simple Ways to Create a Javascript Console in Sublime Text

Download Article
An easy-to-follow guide so you can use Sublime Text to write javascript
Download Article

Javascript consoles are very handy for debugging and getting live results from your script. Although Sublime Text comes with build systems for many other scripting languages, it does not come with a built-in Javascript build system. Many sources will tell you to create a .html page with a link to the .js file, then use a web browser console to see the results of your code. This equates to constant window-switching and browser reloading; leading to frustration, heartache, and ultimately inefficiency. Fortunately, constructing your own Javascript build system for Sublime Text is quick and easy!

Things You Should Know

  • Launch Sublime Text and build a new system.
  • Replace the existing code with the code here, save it, then run it as a saved file to debug.
  • Alternatively, open Node.js and build a new system in Sublime Text.
Method 1
Method 1 of 2:

Using JSC (Mac OS X)

Download Article

Setting Up

  1. How.com.vn English: Step 1  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.
  2. How.com.vn English: Step 2  Go to Tools > Build System > New Build System in the top bar.
    Advertisement
  3. How.com.vn English: Step 3  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"}
  4. Step 4  Save the file as JSC.sublime-build in the default "user" folder.
    Now you have created your build system!
  5. Advertisement

Using the Console

  1. How.com.vn English: Step 1  Open the Javascript file that you want to run in Sublime Text.
  2. How.com.vn English: Step 2  Use debug() instead of console.log() in your script.
  3. How.com.vn English: Step 3  Go to Tools > Build System in the top bar and select JSC.
    This is the build system that you just created.
  4. How.com.vn English: Step 4  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!
  5. Advertisement
Method 2
Method 2 of 2:

Using Node.js

Download Article

Setting Up

  1. How.com.vn English: Step 1  Download the...
    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.
  2. How.com.vn English: Step 2  Go to Tools > Build System > New Build System in the top bar.
  3. How.com.vn English: Step 3  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.
  4. Step 4  Save the file as node.sublime-build in the default "user" folder.
    Now you have created your build system!
  5. Advertisement

Using the Console

  1. How.com.vn English: Step 1  Open the Javascript file that you want to run in Sublime Text.
  2. How.com.vn English: Step 2  Go to Tools > Build System in the top bar and select node.
    This is the build system that you just created.
  3. How.com.vn English: Step 3  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. Advertisement

Community Q&A

Search
Add New Question
  • Question
    When I type console.log(), why does nothing show up in the console?
    How.com.vn English: Community Answer
    Community Answer
    Because you need to make a build to the current file, using either the build shortcut (Ctrl+B for Windows, and ⌘ Command+B for Mac) or by choosing "Build" from the "Tools" menu.
  • Question
    What of using the Linux platform?
    How.com.vn English: Community Answer
    Community Answer
    On Linux, go with the node solution. I have tried on Linux Mint 19.1, and it works perfectly.
  • Question
    Where is the user folder located on MAC or how do you navigate to it?
    How.com.vn English: Community Answer
    Community Answer
    The user folder is located here:Mac HD > Users > yourMacUsername > Library > Application Support > Sublime Text 3 > Packages > User If you're not able to see the 'Library' folder within your MacUsername folder do the following:1. In Finder navigate to Mac HD > Users > yourMacUsername folder2. In Finder, goto View > Show View Options... 3. Check the box that says 'Show Library Folder'
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!

      Things You’ll Need

      • A computer
      • Sublime Text (a programming text editor)
      • An internet connection and browser (for Node.js method)

      About This Article

      How.com.vn is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, volunteer authors worked to edit and improve it over time. This article has been viewed 225,712 times.
      How helpful is this?
      Co-authors: 5
      Updated: June 12, 2023
      Views: 225,712
      Categories: JavaScript
      Thanks to all authors for creating a page that has been read 225,712 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement