How to run node app with sublime text

前端 未结 6 559
旧巷少年郎
旧巷少年郎 2021-02-03 12:38

How would you run node app with sublime text? Like this, open the file app.js in sublime, go to menu->tools->build, and it just runs. Simple like that

相关标签:
6条回答
  • 2021-02-03 12:55

    What is going on is that you don't have the right PATH setup for your terminal.

    try this command in a regular terminal:

    > which node
    

    I peronaly get this:

    /usr/local/bin/node
    

    As you can see this path is not in you environement path to add it in a regular terminal you would edit .bashrc or .bash_profile and add this line

    export PATH=/usr/local/bin:$PATH
    

    Here well you just have to look at the doc and find out that you need to modify the configuration file.

    If you have a JavaScript file open, by selecting selecting Tools -> Build Systems -> Nodejs and then hitting Ctrl + B, you will activate the node build system on your file and node will try to run it. You may need to add a path variable to the settings object for this if your node executable is not found

    Look at this.

    0 讨论(0)
  • 2021-02-03 12:56

    Cmd+Shift+P , search for "Nodejs::Default File Settings" ,it will open file "Node.js.sublime-settings". you'll see:

    {
      // save before running commands
      "save_first": true,
      // if present, use this command instead of plain "node"
      // e.g. "/usr/bin/node" or "C:\bin\node.exe"
      "node_command": false,
      // Same for NPM command
      "npm_command": false,
    
      "expert_mode": false,
    
      "ouput_to_new_tab": false
    }
    

    modify

    "node_command": false,

    to

    "node_command": "/usr/local/bin/node",

    if the node path is not the same with above, find it and change to yours.

    0 讨论(0)
  • 2021-02-03 13:03

    To run nodejs on sublime text, install node package "node dev" then create a sublime text build, the code should look like this

    {
      "cmd": ["node-dev", "$file"],
      "selector" : "source.js",
      "path" : "/usr/local/bin"
    }
    

    Now to run a nodejs app, go to menu->tools->build.

    0 讨论(0)
  • 2021-02-03 13:05

    Create a build sytem with this code:

    {
       "cmd": ["node", "$file"],
       "selector" : "source.js"
    }
    
    0 讨论(0)
  • 2021-02-03 13:07

    If you want to fix the plugin's path yourself. One option is changing Nodejs.sublime-build. It's located in the packages directory of sublime:

    Mac: ~/Library/Application Support/Sublime Text 2/Packages/Nodejs/Nodejs.sublime-build 
    
    Linux: ~/.config/sublime-text-2/Packages/Nodejs/Nodejs.sublime-build
    

    Note: On latest OS X versions the Library folder is hidden. If that's the case, from the menu select Go > Go to Folder... and type ~/Library.

    Change "cmd": ["node", "$file"] to "cmd": ["/usr/local/bin/node", "$file"]
    
    {
      "cmd": ["/usr/local/bin/node", "$file"],
      "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
      "selector": "source.js",
      "shell":true,
      "encoding": "cp1252",
      "windows":
        {
            "cmd": ["taskkill /F /IM node.exe & node", "$file"]
        },
      "linux":
        {
            "cmd": ["killall node; node", "$file"]
        }
    }
    

    Lastly, open your *.js file and press command + b. Everything should just work fine now.

    Linux Users: This file is identical across all operating systems. Finding the path to Nodejs.sublime-build may require running a search. In most cases it's located in ~/.config/sublime-text-2/Packages/Nodejs/Nodejs.sublime-build

    0 讨论(0)
  • 2021-02-03 13:19

    On xubuntu, I made the build command in Nodejs.sublime-build explicity use the terminal:

    "cmd": ["xfce4-terminal", "--command", "node $file"]

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