admin管理员组文章数量:1296506
I tried to run javascript code from SUBLIME TEXT 3 but no works. I tried by setting the build system, once i open it shows me:
{
"shell_cmd": "make"
}
i change it by:
{
"shell_cmd": ["C:/Program Files/nodejs/node.exe", "$file"],
"selector": "source.js"
}
but the package no appear in build system. How can i solve this problem?
I have already installed NodeJS in my pc.
I tried to run javascript code from SUBLIME TEXT 3 but no works. I tried by setting the build system, once i open it shows me:
{
"shell_cmd": "make"
}
i change it by:
{
"shell_cmd": ["C:/Program Files/nodejs/node.exe", "$file"],
"selector": "source.js"
}
but the package no appear in build system. How can i solve this problem?
I have already installed NodeJS in my pc.
Share Improve this question asked Aug 11, 2016 at 4:36 VolazhVolazh 1462 silver badges13 bronze badges 8- @luke_aus problem is that the package that i created no appears on the build system. – Volazh Commented Aug 11, 2016 at 5:10
- did you save it? Its a new file that you are creating, so you need to save it. Save it as 'Javascript' cause that sounds like a sensible description – lukeaus Commented Aug 11, 2016 at 5:13
- yes, i saved it into the sublime package. but as i mentioned before, no appear in build system pallete. – Volazh Commented Aug 11, 2016 at 5:14
- I had the wrong Instructions... should be: did you change the build system to use javascript? That needs to be done in addition to making the build system. Go to Tools --> Build System --> Javascript (or whatever you called the file you saved the build system in) – lukeaus Commented Aug 11, 2016 at 5:17
- yes i did. i went directly to change the build system by the new created one, but problem is that the package that i try to create no appears .. – Volazh Commented Aug 11, 2016 at 5:20
6 Answers
Reset to default 3When I tried it before I made a new build system and pasted this
{
"cmd": ["C:/Program Files/nodejs/node.exe", "$file"],
"selector": "source.js",
}
I don't see shell_cmd
mentioned in the official Build Systems documentation and it doesn't work for in Sublime Text (Build 3119).
Update: If I'm interpreting error message in the console correctly, shell_cmd
does not accept any arguments, hence you cannot pass $file
!
Anyway, the following works just fine for me:
{
"cmd": ["node", "$file"],
"selector": "source.js",
"windows" : {
"shell": true
}
}
Make sure you save the as whatever.sublime-build
in Packages/User
. That's the default location when you're using the dialog to create a new build system (Tools > Build System > New Build System).
Also, I see no reason to put the full path to node
, since the Node.js installer adds it to your PATH environmental variable. If you want use an absolute path, you should probably follow Windows conventions and use back-slashes – just make sure they're escaped, which is JSON convention (e.g. C:\\Program Files\\nodejs\\node.exe
).
1. For linux based os.
first install nodejs
sudo apt-get install nodejs-legacy
then create a build system under tools panel on sublime text, save it as javascript.sublime-build or anyword.sublime-build
then paste this code and save,
{
"cmd": ["node", "$file"],
"selector": "source.js"
}
make sure that the saving directory is:
/home/username/.config/sublime-text-3/Packages/User/
then on build systems select which build system you want. in this case select javascript.
example. create a new file like index.js and add this code.
var add = function(x,y){
return x+y;
}
console.log(add(2,3));
then press ctl+B key. A console terminal opens at the bottomm of the page.
5
[Finished in 0.0s]
- For Windows Users
first you have to install nodeJS. If it is already installed open mand prompt and type where node
it will show the directory where it is installed, it must be here -
C:\Program Files\nodejs\node.exe
copy this path and go to environment variables Select PATH then EDIT then NEW and then PASTE the copied address and then click OK
Now open sublime text goto TOOLS > BUILD SYSTEM >NEW BUILD SYSTEM Paste the code given below
{
"shell_cmd": ["C:/Program Files/nodejs/node.exe", "$file"],
"selector": "source.js"
}
Save it with name JavaScript.sublime-build
in location -
C:\Users\Acer\AppData\Roaming\Sublime Text 3\Packages\User
NOTE that here "Acer" is username. Now restart Sublime text and you will able to see a new build system named as JavaScript,
No answer has file_patterns
in it which is required, well at least I had trouble getting it to work without it.
{
"selector": "source.js",
"file_patterns": ["*js"],
"cmd": ["C:/Program Files/nodejs/node.exe", "$file"],
}
More info on Sublime Texts' page:
https://www.sublimetext./docs/build_systems.html
1. For Mac
This worked for me. I had all my files in the same dir.
{
"cmd": ["sh", "-c", "node < input.txt $file > output.txt"],
"selector": "source.js"
}
本文标签: nodejsRun JavaScript code SublimeTextStack Overflow
版权声明:本文标题:node.js - Run JavaScript code SublimeText - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741639060a2389809.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论