Sublime TEXT3 Configuring the node. JS Run command

Source: Internet
Author: User
Tags install node sublime text

-

In the sublime text can easily configure the new compile Run command, the following is the Chinese version of the English menu, please direct control.

You first need to install node locally, and the default node will be added to the environment variables of the system so that the node command does not need to be executed under the installation path.


Select "New compiled System" and insert the following code in the open file:

  
 
  1. {
  2. "cmd": ["node", "$file"],
  3. "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
  4. "selector": "source.js",
  5. "shell":true,
  6. "encoding": "utf-8",
  7. "windows":
  8. {
  9. "cmd": ["node", "$file"]
  10. },
  11. "linux":
  12. {
  13. "cmd": ["killall node; node", "$file"]
  14. }
  15. }

Save As Node.sublime-build, later want to run the current file, directly using the shortcut key "Ctrl+b", the above code is shared by most of the online tutorial, but this configuration has a problem, in the Windows system, This creates a new node process for each build, consumes 1 ports and prompts the port to be occupied the next time you want to build

  
 
  1. function logger(req,res,next){
  2. console.log(‘%s %s‘,req.method,req.url);
  3. next();
  4. }
  5. function hello(req,res){
  6. res.setHeader(‘Content-Type‘,‘text/plain‘);
  7. res.end(‘hello world‘);
  8. }
  9. var connect=require(‘connect‘);
  10. var app=connect();
  11. app.use(logger).use(hello).listen(3000);
For example, the Connect middleware program above listens for 3000 ports, there is no error on the first build, but the following error occurs on the second build.


On the internet, someone has given the following configuration to solve the problem:

  
 
  1. {
  2. "cmd": ["node", "$file"],
  3. "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
  4. "selector": "source.js",
  5. "shell":true,
  6. "encoding": "utf-8",
  7. "windows":
  8. {
  9. "cmd": ["taskkill /F /IM node.exe", ""],
  10. "cmd": ["node", "$file"]
  11. },
  12. "linux":
  13. {
  14. "cmd": ["killall node; node", "$file"]
  15. }
  16. }
The intent of this configuration is tocmd command preceded by a Kill node process command, but the actual test did not work, and finally I changed the first line of command to the following to execute two commands, on the Windows system does not appear above the problem.

  
 
  1. {
  2. "cmd": "taskkill /F /IM node.exe & node \"$file\"",
  3. "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
  4. "selector": "source.js",
  5. "shell":true,
  6. "encoding": "utf-8",
  7. }



    From for notes (Wiz)

    Sublime TEXT3 Configuring the node. JS Run command

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.