-
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:
{
"cmd": ["node", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell":true,
"encoding": "utf-8",
"windows":
{
"cmd": ["node", "$file"]
},
"linux":
{
"cmd": ["killall node; node", "$file"]
}
}
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
function logger(req,res,next){
console.log(‘%s %s‘,req.method,req.url);
next();
}
function hello(req,res){
res.setHeader(‘Content-Type‘,‘text/plain‘);
res.end(‘hello world‘);
}
var connect=require(‘connect‘);
var app=connect();
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:
{
"cmd": ["node", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell":true,
"encoding": "utf-8",
"windows":
{
"cmd": ["taskkill /F /IM node.exe", ""],
"cmd": ["node", "$file"]
},
"linux":
{
"cmd": ["killall node; node", "$file"]
}
}
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.
{
"cmd": "taskkill /F /IM node.exe & node \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell":true,
"encoding": "utf-8",
}
From for notes (Wiz)
Sublime TEXT3 Configuring the node. JS Run command