如何在sublime text 调试3调试nodejs

如何在sublime text 3调试nodejs_百度知道
如何在sublime text 3调试nodejs
提问者采纳
请继续“追问”TOOLS里面选择BUILD为NODEJS不就好了吗,可另外向我求助..,还有不懂的地方,互相理解,;答题不易。 如你还有别的问题。你的采纳是我前进的动力。debug的话还是推荐你用chrome?当然如果没有的话你就new一个
来自团队:
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁用了才知道!MAC下Sublime Text3如何安装插件? - 金哲博客
真正的简约是在纷繁中构建秩序
阅读 27,570 次
作者:野草
用了Sublime Text&好多年了!一直都是手写代码没去注意插件这个。现在发现插件真心好用,真是有点相见恨晚的感觉。安装插件前大家要安装很多东西,JAVA SDK&NODEJS&git 等等。还有一些需要用NPM来安装。
1.打开sublime text3后按快捷键control+`后下面会出来东西,然后输入如下命令。
import urllib.request, pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())
2.快捷键command+shift+p后会出来列表,找到Package Control:Install Package。呆一会会出来插件列表,这个地方搜索你要找的插件名称。我觉得这里设计挺麻烦的,每次都要按这个安装,还好安装好一次就没啥事了。
3.我目前装了以下插件。
Minify:压缩JS的
JSFormat:一款格式化代码的,按control+alt+f 。
SideBarEnhancements:侧边栏按目录显示。
使用键盘“←”和“→”可快速切换上下篇sublime text 3 插件:HTML-CSS-JS Prettify - FED社区
sublime text 3 插件:HTML-CSS-JS Prettify
这是一款集成了格式化(美化)html、css、js三种文件类型的插件。插件依赖于nodejs,因此需要事先安装nodejs,然后才可以正常运行。
插件安装完成后,快捷键ctrl+shift+H完成当前文件的美化操作。插件对html、css文件的美化不是非常满意,但还可以,后面将说明如何修改css美化脚本,此为后话。
下面这是我的插件配置,主要修改了缩进符为制表符。
// Details: /victorporof/Sublime-HTMLPrettify#using-your-own-jsbeautifyrc-options
// Documentation: /einars/js-beautify/
&brace_style&: &collapse&, // &expand&, &end-expand&, &expand-strict&
&indent_char&: &\t&,
&indent_scripts&: &keep&, // &separate&, &normal&
&indent_size&: 1,
&max_preserve_newlines&: 10,
&preserve_newlines&: true,
&unformatted&: [&pre&, &code&, &textarea&, &title&],
&wrap_line_length&: 0
&indent_char&: &\t&,
&indent_size&: 1
&brace_style&: &collapse&, // &expand&, &end-expand&, &expand-strict&
&break_chained_methods&: false,
&e4x&: false,
&eval_code&: false,
&indent_char&: &\t&,
&indent_level&: 0,
&indent_size&: 1,
&indent_with_tabs&: true,
&jslint_happy&: true,
&keep_array_indentation&: false,
&keep_function_indentation&: false,
&max_preserve_newlines&: 10,
&preserve_newlines&: true,
&space_before_conditional&: true,
&space_in_paren&: false,
&unescape_strings&: false,
&wrap_line_length&: 0
插件对css的美化不尽如人意,会导致css注释的下一行有个空格符,并且删除了本该有的换行。
修改css美化脚本,从菜单-&Preferences-&Browse Packages,打开HTML-CSS-JS Prettify/scripts/beautify-css.js文件,修改如下:
* @author Ariya Hidayat.
* @author ydr.me
* @link /post/sublime-text-3-plugin-html-css-js-prettify.html
* @time 日14:25:03
* 修改以适配 sublime text 3 html-css-js-prettify 插件
Copyright (C) 2013 Sencha Inc.
Copyright (C) 2012 Sencha Inc.
Copyright (C) 2011 Sencha Inc.
Author: Ariya Hidayat.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the &Software&), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED &AS IS&, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
/*jslint continue: true, indent: 4 */
/*global exports:true, module:true, window:true */
(function () {
'use strict';
function cssbeautify(style, opt) {
var options, index = 0,
length = style.length,
blocks, formatted = '',
ch, ch2, str, state, State, depth, quote, comment,
openbracesuffix = true,
autosemicolon = false,
trimRight,
// 记录第一个字符,以适配于html中的style标签里的样式美化
firstChar = '';
options = arguments.length & 1 ? opt : {};
if (options.indent === undefined) {
options.indent = '';
options.indent_size = options.indent_size || 1;
options.indent_char = options.indent_char || '\t';
while (options.indent_size--) {
options.indent += options.indent_
if (typeof options.indent === 'undefined') {
options.indent = ' ';
if (typeof options.openbrace === 'string') {
openbracesuffix = (options.openbrace === 'end-of-line');
if (typeof options.autosemicolon === 'boolean') {
autosemicolon = options.
function isWhitespace(c) {
return (c === ' ') || (c === '\n') || (c === '\t') || (c === '\r') || (c === '\f');
function isQuote(c) {
return (c === '\'') || (c === '&');
// FIXME: handle Unicode characters
function isName(c) {
return (ch &= 'a' && ch &= 'z') ||
(ch &= 'A' && ch &= 'Z') ||
(ch &= '0' && ch &= '9') ||
'-_*.:#[]'.indexOf(c) &= 0;
function appendIndent() {
for (i = i & 0; i -= 1) {
formatted += options.
function openBlock() {
formatted = trimRight(formatted);
if (openbracesuffix) {
formatted += ' {';
formatted += '\n';
appendIndent();
formatted += '{';
if (ch2 !== '\n') {
formatted += '\n';
depth += 1;
function closeBlock() {
depth -= 1;
formatted = trimRight(formatted);
if (formatted.length & 0 && autosemicolon) {
last = formatted.charAt(formatted.length - 1);
if (last !== ';' && last !== '{') {
formatted += ';';
formatted += '\n';
appendIndent();
formatted += '}';
blocks.push(formatted);
formatted = '';
if (String.prototype.trimRight) {
trimRight = function (s) {
return s.trimRight();
// old Internet Explorer
trimRight = function (s) {
return s.replace(/\s+$/, '');
AtRule: 1,
Selector: 3,
Ruleset: 4,
Property: 5,
Separator: 6,
Expression: 7,
depth = 0;
state = State.S
blocks = [];
// We want to deal with LF (\n) only
style = style.replace(/\r\n/g, '\n');
firstChar = (style.match(/^[ \t]+/) || [''])[0]
while (index & length) {
ch = style.charAt(index);
ch2 = style.charAt(index + 1);
index += 1;
// Inside a string literal?
if (isQuote(quote)) {
formatted +=
if (ch === quote) {
if (ch === '\\' && ch2 === quote) {
// Don't treat escaped character as the closing quote
formatted += ch2;
index += 1;
// Starting a string literal?
if (isQuote(ch)) {
formatted +=
// Comment
if (comment) {
formatted +=
if (ch === '*' && ch2 === '/') {
formatted += ch2;
index += 1;
if (ch === '/' && ch2 === '*') {
formatted +=
formatted += ch2;
index += 1;
if (state === State.Start) {
if (blocks.length === 0) {
if (isWhitespace(ch) && formatted.length === 0) {
// Copy white spaces and control characters
if (ch &= ' ' || ch.charCodeAt(0) &= 128) {
state = State.S
formatted +=
// Selector or at-rule
if (isName(ch) || (ch === '@')) {
// Clear trailing whitespaces and linefeeds.
str = trimRight(formatted);
if (str.length === 0) {
// If we have empty string after removing all the trailing
// spaces, that means we are right after a block.
// Ensure a blank line as the separator.
if (blocks.length & 0) {
formatted = '\n\n';
// After finishing a ruleset or directive statement,
// there should be one blank line.
if (str.charAt(str.length - 1) === '}' ||
str.charAt(str.length - 1) === ';') {
formatted = str + '\n\n';
// After block comment, keep all the linefeeds but
// start from the first column (remove whitespaces prefix).
while (true) {
ch2 = formatted.charAt(formatted.length - 1);
if (ch2 !== ' ' && ch2.charCodeAt(0) !== 9) {
formatted = formatted.substr(0, formatted.length - 1);
formatted +=
state = (ch === '@') ? State.AtRule : State.S
if (state === State.AtRule) {
// ';' terminates a statement.
if (ch === ';') {
formatted +=
state = State.S
// '{' starts a block
if (ch === '{') {
str = trimRight(formatted);
openBlock();
state = (str === '@font-face') ? State.Ruleset : State.B
formatted +=
if (state === State.Block) {
// Selector
if (isName(ch)) {
// Clear trailing whitespaces and linefeeds.
str = trimRight(formatted);
if (str.length === 0) {
// If we have empty string after removing all the trailing
// spaces, that means we are right after a block.
// Ensure a blank line as the separator.
if (blocks.length & 0) {
formatted = '\n\n';
// Insert blank line if necessary.
if (str.charAt(str.length - 1) === '}') {
formatted = str + '\n\n';
// After block comment, keep all the linefeeds but
// start from the first column (remove whitespaces prefix).
while (true) {
ch2 = formatted.charAt(formatted.length - 1);
if (ch2 !== ' ' && ch2.charCodeAt(0) !== 9) {
formatted = formatted.substr(0, formatted.length - 1);
appendIndent();
formatted +=
state = State.S
// '}' resets the state.
if (ch === '}') {
closeBlock();
state = State.S
formatted +=
if (state === State.Selector) {
// '{' starts the ruleset.
if (ch === '{') {
openBlock();
state = State.R
// '}' resets the state.
if (ch === '}') {
closeBlock();
state = State.S
formatted +=
if (state === State.Ruleset) {
// '}' finishes the ruleset.
if (ch === '}') {
closeBlock();
state = State.S
if (depth & 0) {
state = State.B
// Make sure there is no blank line or trailing spaces inbetween
if (ch === '\n') {
formatted = trimRight(formatted);
formatted += '\n';
// property name
if (!isWhitespace(ch)) {
formatted = trimRight(formatted);
formatted += '\n';
appendIndent();
formatted +=
state = State.P
formatted +=
if (state === State.Property) {
// ':' concludes the property.
if (ch === ':') {
formatted = trimRight(formatted);
formatted += ': ';
state = State.E
if (isWhitespace(ch2)) {
state = State.S
// '}' finishes the ruleset.
if (ch === '}') {
closeBlock();
state = State.S
if (depth & 0) {
state = State.B
formatted +=
if (state === State.Separator) {
// Non-whitespace starts the expression.
if (!isWhitespace(ch)) {
formatted +=
state = State.E
// Anticipate string literal.
if (isQuote(ch2)) {
state = State.E
if (state === State.Expression) {
// '}' finishes the ruleset.
if (ch === '}') {
closeBlock();
state = State.S
if (depth & 0) {
state = State.B
// ';' completes the declaration.
if (ch === ';') {
formatted = trimRight(formatted);
formatted += ';\n';
state = State.R
formatted +=
if (ch === '(') {
if (formatted.charAt(formatted.length - 2) === 'l' &&
formatted.charAt(formatted.length - 3) === 'r' &&
formatted.charAt(formatted.length - 4) === 'u') {
// URL starts with '(' and closes with ')'.
state = State.URL;
if (state === State.URL) {
// ')' finishes the URL (only if it is not escaped).
if (ch === ')' && formatted.charAt(formatted.length - 1 !== '\\')) {
formatted +=
state = State.E
// The default action is to copy the character (to prevent
// infinite loop).
formatted +=
formatted = blocks.join('') +
if (firstChar) {
formatted = formatted.split('\n').map(function (fm) {
return firstChar + fm + '\n';
formatted = formatted.join('');
if (typeof exports !== 'undefined') {
// Node.js module.
module.exports.css_beautify =
} else if (typeof window === 'object') {
// Browser loading.
window.css_beautify =
4、参考资料
专辑《sublime text 3》创建于 日 10:41:00。
10个月前 文章
10个月前 文章
10个月前 文章
10个月前 文章
10个月前 文章
10个月前 文章
10个月前 文章
10个月前 文章
发布于 10个月前 更新于 10个月前&1次 被阅读 5,031 次 被评论
FED社区 FED社区(前端开发社区 The Front-End Development community)是为前端开发者提供的一个专业技术服务社区。为前端开发者提供文章发表、智慧提问、链接分享、交流分享等专业技术服务。
&2014 FrontEndDev.org MIT
1,981,696,272 UZYhZdddwEEHjqdbJeEa 435在windows环境下基于sublime&text3的node.js开发环境搭建
首先安装sublime text3,百度一堆,自己找吧。理论上sublime
text2应该也可以。我只能说一句:这个软件实在是太强悍了。
跨平台,丰富的插件体系,加上插件基本上就是一个强悍的ide了。目前我在使用的主要是Emmet、Python、还有一些格式化的插件(xml,json),加上这次安装的node.js。
node.js的安装就不用多说了,直接http://nodejs.org/
点击install下载window版本的安装程序后安装即可。默认的安装会将安装目录加到path环境变量中,这一步是为了后续使用node的时候,可以不用带路径,当然,后续在sublime
text中安装好nodejs插件之后,也可以对node的路径进行一些自定义的设置。为了使用方便,建议增加到path环境变量。
SublimeText-Nodejs插件(/tanepiper/SublimeText-Nodejs)
原本在sublime
text的插件库里面有nodejs的插件,但是经过尝试安装后,发现无法修改编译设置,没找到Nodejs.sublime-build文件,后来在github上面看了下人家的安装说明之后再重新安装的。
安装Package Control;运行Sublime,按下快捷键Ctrl +
`;在控制台中输入如下并回车;
import urllib2,os, h =
'2debe27c334aa' +
'bf8c4e67d14fb98a6d7e1'; pf = 'Package
Control.sublime-package'; ipp = sublime.installed_packages_path();
os.makedirs( ipp ) if not os.path.exists(ipp) else N
urllib2.install_opener( urllib2.build_opener(
urllib2.ProxyHandler()) ); by = urllib2.urlopen(
'http://packagecontrol.io/' + pf.replace(' ', ' ')).read(); dh =
hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb'
).write(by) if dh == h else N print('Error validating download
(got %s instead of %s), please try manual install' % (dh, h) if dh
!= h else 'Please restart Sublime Text to finish installation')
import urllib.request,os, h =
'2debe27c334aa' +
'bf8c4e67d14fb98a6d7e1'; pf = 'Package
Control.sublime-package'; ipp = sublime.installed_packages_path();
urllib.request.install_opener( urllib.request.build_opener(
urllib.request.ProxyHandler()) ); by = urllib.request.urlopen(
'http://packagecontrol.io/' + pf.replace(' ', ' ')).read(); dh =
hashlib.sha256(by).hexdigest(); print('Error validating download
(got %s instead of %s), please try manual install' % (dh, h)) if dh
!= h else open(os.path.join( ipp, pf), 'wb' ).write(by)
安装也有二种方式:
1、直接下载压缩包后解压到sublime
text的package目录中。查看package目录在哪可以通过菜单栏中的Preferences--&浏览程序包Browse
Packages直接打开package目录。
2、使用git命令下载到package目录(git clone
/tanepiper/SublimeText-Nodejs
"D:\ProgramFiles\Sublime Text 3\Data\Packages\nodejs")
修改编译选项,在package目录下的nodejs目录中,打开Nodejs.sublime-build,原始内容如下:
// 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": "C:/Program
Files/nodejs/node.exe",
// Same for NPM command
"npm_command": "C:/Program
Files/nodejs/npm",
// as 'NODE_PATH' environment variable
for node runtime
"node_path": false,
"expert_mode": false,
"ouput_to_new_tab": false
有2个地方需要修改,一个是编码,为了避免乱码code,需要改成cp936;另外一个是cmd命令,本身如果只是想简单的运行nodejs程序的话,windows下面的cmd可以直接
"cmd": ["node",
"$file"],但是这样非常不利于开发环境,因为这样的话每次build都会重新启动一个node.exe进程,且会占用一个端口,这肯定是我们不希望的。上文中的cmd原本是想在启动node.exe之前讲node.exe进程都杀掉,然后再启动node.exe,但是这个命令写的不对,直接使用的话是编译不成功的。对cmd命令需要做简单的处理,修改好之后的Nodejs.sublime-build文件内容如下:
"cmd": ["C:/Program
Files/nodejs/node.exe","-p" "$file"],
"file_regex": "^[ ]*File "(...*?)",
line ([0-9]*)",
"selector": "source.js",
"shell":true,
//"encoding": "cp1252",
"encoding": "utf8",
"windows":
"cmd": ["taskkill /F /IM node.exe & node", "$file"]
"cmd": ["C:/Program
Files/nodejs/node.exe", "$file"]
"cmd": [" node",
"cmd": [" node
重启sublime
text之后,配置就算完成了。我们写一小段代码来验证一下是否可以正常运行。
var http = require('http');
var os = require('os');
http.createServer(function (request,
response) {
response.writeHead(200,
{'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3000);
console.log('Server running at
http://127.0.0.1:3000/');
Ctrl+b编译这段代码之后,sublime text窗口中就会显示
Server running at
http://127.0.0.1:3000/
若之前有运行的node进程在,则会先杀掉node进程,再启动node,显示如下:
成功: 已终止进程 "node.exe",其 PID 为
Server running at
http://127.0.0.1:3000/
到此,服务端算是启动成功,打开浏览器,输入http://127.0.0.1:3000/,页面显示Hello
World则表示交互正常。
开发环境就算是基本搭建完毕了,准备接下来一篇文章讲讲怎么使用自带的NPM包管理工具,NPM能解决nodejs代码部署上的很多问题。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。javascript - Sublime Text 3: Settings for NodeJS Build System - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
I downloaded the Nodejs plugin, using Package Control in Sublime Text 3 editor.
I can't config the original settings file, without setting a different javascript build system.
..\Sublime Text 3\Packages\User\Nodejs.sublime-settings
// 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": "C:\\Program Files\\nodejs\\node.exe",
// Same for NPM command
"npm_command": "C:\\Users\\fraballi\\AppData\\Roaming\\npm",
// as 'NODE_PATH' environment variable for node runtime
"node_path": false,
"expert_mode": false,
"ouput_to_new_tab": false
Console error
[Finished in 0.1s with exit code 1]
[cmd: ['taskkill /F /IM node.exe & node', 'C:\Users\..\the\path\to\file\js']]
[dir: C:\Users\..\the\path\to\file\js]
[path: C:\Windows\system32;C:\WC:\Windows\System32\WC:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\idmu\C:\Program Files (x86)\GTK2-Runtime\c:\xampp\C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\ProgramData\ComposerSetup\C:\Program Files\Java\jre1.8.0_25\C:\ProgramData\chocolatey\C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\nodejs\;\C:\Program Files (x86)\Git\C:\Program Files (x86)\Git\C:\Program Files (x86)\GitExtensions\;C:\Users\fraballi\AppData\Roaming\npm]
Know someone who can answer?
Share a link to this
via , , , or .
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Browse other questions tagged
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 sublime3 nodejs 调试 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信