PDF download Download Article
An easy-to-follow guide so you can use Sublime Text to write javascript
PDF download 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)

PDF download Download Article

Setting Up

    • 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.
  1. Advertisement
  2. Replace anything else in it:
     { 
     "cmd" 
     : 
     [ 
     "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc" 
     , 
     "$file" 
     ], 
     "selector" 
     : 
     "source.js" 
     } 
    
  3. Now you have created your build system!
  4. Advertisement

Using the Console

  1. This is the build system that you just created.
  2. 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!
  3. Advertisement
Method 2
Method 2 of 2:

Using Node.js

PDF download Download Article

Setting Up

  1. 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. 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.
  3. Now you have created your build system!
  4. Advertisement

Using the Console

  1. This is the build system that you just created.
  2. 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!
  3. Advertisement

Community Q&A

Search
Add New Question
  • Question
    When I type console.log(), why does nothing show up in the console?
    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?
    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?
    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 folder 2. In Finder, goto View > Show View Options... 3. Check the box that says 'Show Library Folder'
Ask a Question
      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

      Thanks to all authors for creating a page that has been read 226,281 times.

      Is this article up to date?

      Advertisement