Node.js build system in Sublime Text 2

后端 未结 13 2172
耶瑟儿~
耶瑟儿~ 2020-12-13 06:30

I justed started learning JavaScript. While doing that, I got tired of embedding my JavaScript code into an HTML document in order to run it in the browser. I thought it wou

相关标签:
13条回答
  • 2020-12-13 07:19

    Mac users, type which node in terminal. It outputs the path of the node executable, which in most cases is /usr/local/bin/node. Now create a new build system (Tools > Build System > New Build System) with the following settings in Sublime Text.

    {   
      "cmd": ["/usr/local/bin/node", "$file"],   
      "selector": "source.js"   
    }
    
    0 讨论(0)
  • 2020-12-13 07:19

    May be it depends on environment variables -- try to use full path to node instead of just "nodejs". It worked for me on Mac OS (e.g. /usr/local/node instead of just node)

    0 讨论(0)
  • 2020-12-13 07:27

    The method #2 of the link below solved for me:

    http://www.wikihow.com/Create-a-Javascript-Console-in-Sublime-Text

    0 讨论(0)
  • Tested on Ubuntu Linux. Use a file selector as below:

    {
      "cmd": ["node", "$file"],
      "selector": "*.js"
    }
    
    0 讨论(0)
  • 2020-12-13 07:28

    Normally

    "cmd":["node",$file]
    

    would work. However there is no way to stop the server than. I've found out the best solution which opens server in new console and the closes it automatically. I also works fine with supervisors or node-inspector

    "cmd" : ["start", "cmd.exe", "/C", "node", "$file"]
    

    I hope It'll help

    0 讨论(0)
  • 2020-12-13 07:28

    I'm using windows and I created a New Build System with this content:

    {
    "cmd": ["node", "$file"],
    "selector": "source.js",
    "working_dir": "${project_path:${folder}}",
    "path": "C:\\Program Files\\nodejs"
    }
    

    And after a ran a JavaScript file with sucessul inside Sublime.

    My JavaScript file has this content:

    var a = 10;
    var b = 20;
    
    var resultado = a + b;
    
    console.log('resultado:', resultado);

    0 讨论(0)
提交回复
热议问题