Built in Nodejs- Nodejs development environment

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Learning nodejs, need a good development tools, don't want no smart tips and not friendly type Notepad write


1 from the www.nodejs.org download webstorm, Eclipse, sublime2, etc. Webstorm tips and auto complete function better, sublime text2 has a lot of plug-ins can be used, GIT, SVN, automatic alignment, command line, it was an editor. Due to the integrated many plugins, here I choose sublime. Here's how to use the tool of sublime to write Nodejs code.

1) Download sublime and install, download list: http://www.sublimetext.com/2

2) Download the sublime nodejs plugin, Nodejs plugin is integrated into sublime, download address: https://github.com/tanepiper/SublimeText-Nodejs

3) Extract the zip file, and rename the folder"Nodejs"

4) Open sublime, " preference" --> " Browse packages", open a directory, the directory is stored in many language IDE plug-in.

5) Copy the "Nodejs" folder in this directory. Is this OK? Sauce appearance is not enough, but also change the configuration file.

6) Open the Nodejs folder, find the file "Nodejs.sublime-build", drag and drop sublime, display:


{
  "cmd": ["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"]
    }
}




Need to change the top mark place, want to change the encoding to GB2312 or utf8, if this property may lead to build nodejs code terminal display garbled does not change.

Second mark, if taskkill /F /IM node.exe, in the build each time, will generate a node.exe process. This is just terrible. I'm here to"cmd": ["taskkill","/F", "/IM", "node.exe","&","node", "$file"] . Such as;

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




7) To use sublime to open the file "Nodejs.sublime-settings" or "preference" - "set" package settings "-" "Nodejs" "setting-default" - "to open the file and change into:


{
  // 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"
  // e.g. "/usr/bin/node" or "C:\bin\node.exe"
  "node_command": "D:\\ProgramFiles\nodejs\node.exe",  //Is the Nodejs installation directory
  // Same for NPM command
  "npm_command": "D:\\ProgramFiles\nodejs\npm.cmd",Ditto.  
  // as 'NODE_PATH' environment variable for node runtime
  //"node_path": false,

  "expert_mode": false,

  "ouput_to_new_tab": false
}




Configuration completed,

3 verification, copy the following code into a new file in sublime. And Ctrl+ B compile the code. The immediate window display: Server running at, and then open the browser type in the address and display the contents of Hello nodejs. This is a simple web publishing.


var http = require('http'); 
var os = require('os');   

http.createServer(function (request, response) {   
  response.writeHead(200, {'Content-Type': 'text/plain'});   
  response.end('Hello nodejs\n');   

}).listen(80);   

console.log('Server running at  );



Note: Hope sublime intelligent prompt, create a new file and save the file *.js, and then began to edit JavaScript code, intelligent prompt is displayed.



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Mariah at January 01, 2014 - 12:02 PM