Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run node app with sublime text

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

like image 502
angry kiwi Avatar asked Aug 25 '12 18:08

angry kiwi


People also ask

How to create a Node JS server in Sublime Text?

Create a server.js file write the following code & save the file. Press Ctrl+B to build the node js file. Now you can see in sublime text node js server has started. If you need to prove your skills in the .NET framework, get .NET certified on StudySection.

How to write Python code in Sublime Text?

After you open Sublime Text, you have an empty file. You can write code, but before you do that, go to Tools >> Build System >> Python. Now, after the build system is set, you can save your file ( Ctrl + S ), and don’t forget about the file extension. I named my file “hello.py”.

How to install Sublime Text 3 on Windows?

Now, that we are sure that the Python is correctly installed and paths are added to Environment Variables, you can install and open Sublime Text 3 editor. Click the Windows search icon, and enter “sublime”. A new icon will appear. Click it to open the editor.

What are the best plugins for Sublime Text for JavaScript?

Check out these 3 great and essential Sublime Text plugins every JavaScript and Node developer should know about and use. JsFormat is a JavaScript formatting plugin. Behind the scenes, it uses the command line formatter from jsbeautifier.org to format full or portions of JavaScript and JSON files.


3 Answers

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.

like image 168
govo Avatar answered Oct 07 '22 02:10

govo


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

like image 40
James Harris Avatar answered Oct 07 '22 01:10

James Harris


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.

like image 31
angry kiwi Avatar answered Oct 07 '22 01:10

angry kiwi