JavaScript doesn't run properly


#1

I am using Atom while learning JavaScript and it seems to not be working when I use atom-runner to run it. I create a simple Hello World with document.write but it just gives me an error.

What am I missing? I’ve googled it already and read that I have to launch Atom from the Terminal, but I’d really prefer to not have to do that.


#2

document tends to refer to the HTML page the JS is being run from.

I’m not familiar with atom-runner, but I’m assuming it runs as a REPL (read-eval-print loop) which likely doesn’t have a document.

You may instead want to use try using console.log-ing instead. Maybe also try console.log(typeof document). It’ll likely report that document is undefined, which would explain why it is barfing.


#3

Nope, doesn’t seem to work. Still gives me this:

Unable to find command: node
Are you sure PATH is configured correctly?

ENV PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Error: spawn node ENOENT
at exports._errnoException (util.js:856:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at doNTCallback2 (node.js:465:9)
at process._tickCallback (node.js:379:17)


#4

Have you got Node installed?

It looks like it literally just uses the Node REPL. So it’s assuming you have Node because you’re writing JavaScript, but not finding it. I assume you get a similar response if you write node in your command prompt.


#5

Do I need it installed? I thought Node.js was just for running JavaScript as a server side language.


#6

Well it’s more of a JavaScript runtime (it’s a bit of simplification, it does a bunch of other stuff too), which happens to also be good for servers, etc.

You need it, that’s why the plugin’s not working, but if you’re going to need it in future for other JavaScript related thing, so you’d ought to install it anyway.

In fact, I’m a bit mystified as to how you can even get as far as you have without Node.


#7

Thanks! I installed it you were totally right. console.log works great. Thanks so much!

Yeah, like I said, I am trying to teach myself this stuff using online tutorials and courses and it can be hard sometimes. I haven’t gotten really any answers other than yours in days of asking people and was close to giving up. Seems pretty simple now that I think about it though.

Thanks again.


#8

Excellent! Happy to help!

I remember my early JavaScript days, everything that makes so much sense now was near impenetrable when I started.

Good luck with your learning!