Node.js build system in Sublime Text 2

后端 未结 13 2170
耶瑟儿~
耶瑟儿~ 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:03

    This woks for me in Windows7

    1) Open Sublime Text, Goto "Tools" -> "Build System" -> "New Build System"

    2) Paste this text

    {

    "cmd": ["C:\\Program Files (x86)\\nodejs\\node","$file"]
    

    }

    \\ Escaping character

    3) Save as Node.sublime-build

    4) Write a new js file, and press CTRL+B for build.

    Click here for see image example.

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

    On linux I use this, just make sure you are on your main file

    {
        "shell_cmd": "pkill node ; node $file"
    }
    
    0 讨论(0)
  • 2020-12-13 07:05
    {
        "cmd": ["node","$file"]
    }
    

    works perfectly for me in windows and it shows the output in the sublime window. Although I dont know how to stop the server after from sublime, I have to search and kill the node process.

    Also, check node is in your PATH ;)

    Hope it works for you.

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

    Here is a tip for Windows,

    Most of the answers from this thread is correct but none is complete and at least no answer tells about how to kill existing Node process even if you are able to run node in sublime. So eventually if either of above approach worked for you, You will end up manually killing Node always.

    Here is What I have done for 'Windows':

    1. Open Sublime Text, Goto "Tools" -> "Build System" -> "New Build System"
    2. Above will open a new file, paste below content there, and save it as nodejs.xxx ( use default extension): { "cmd": ["c:/test.bat","$file"] }
    3. Create a file ( c:/test.bat ) and paste this content (both of 2 lines) there:

    taskkill /F /IM "node.exe" "c:/Program Files/nodejs/node.exe" %1

    1. Save it, Switch to Sublime Text and select "Tools" -> "Build System" -> "nodejs"
    2. open any Nodejs Exectuable file and Hit CTRL+B.
    3. You're good to go. :)

    Enjoy noding.

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

    On Windows, the following configuration works:

    {
        "cmd": ["C:\\Program Files\\nodejs\\node.exe", "$file"],
        "selector": "source.js"
    }
    
    0 讨论(0)
  • 2020-12-13 07:10

    I can only see the console output only if the file exists/saved on disk. (for anonymous file I don't see the output either)

    Hope this helps

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