简体   繁体   中英

Building a JavaScript build system in Sublime Text

I'm trying to work on an application using node.js , and am trying to build a JavaScript build system in Sublime Text 3 on my Ubuntu OS. I created a new build system file in Sublime Text called nodey.sublime-build , the contents of which were:

{
    "cmd": ["node","$file","$file_base_name"],
    "working_dir": "${project_path:${folder}}",
    "selector":"*.js"
}

Now, my node.js installation is stored in the following path: /tmp/node-v0.12.7-linux-x64 .

However, when I try to run a JavaScript file called chat.js which is stored in the following location: /opt/lampp/htdocs/chat/chat.js , Sublime Text throws the following error:

[Errno 2] No such file or directory: 'node'
[cmd: ['node', '/opt/lampp/htdocs/chat/chat.js', 'chat']]
[dir: /opt/lampp/htdocs/chat]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]
[Finished]

I'm not really sure if this is the right method for creating a new build system. After building the nodey build system, I went to Tools -> Build System and selected nodey .

What seems to be wrong with my settings?

EDIT:

I ran a sudo apt-get install node inside the same directory as chat.js , and now when I try to run the JavaScript file in Sublime Text, I get this:

[Finished in 0.0s with exit code 1]
[cmd: ['node', '/opt/lampp/htdocs/chat/chat.js', 'chat']]
[dir: /opt/lampp/htdocs/chat]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]

However, even though there are no noticeable errors, the output of the file, which included a console.log("Hello World") , wasn't displayed.

For anyone else encountering the same error, try running the following in your terminal if you're a Linux user:

sudo apt-get install node
sudo apt-get install nodejs-legacy

This solved the problem in my case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM