Thursday, May 2, 2013

I am trying to get used to the Node shell.

per this: A standalone line of code may be run just by typing it in the shell like so...
console.log('Hello World');
...and pressing enter, (which in my case caused "Hello World" to be written on the next line and "undefined" to be written on the line below it), but starting a line of code with a dollar sign opens up the ability to write a series of lines of code. Herein, pressing enter breaks to the next line instead of executing the line beforehand.
per this: Ctrl-C will end a series of lines of codes started by opening up a dollar sign.
per this: I now believe that what I wrote above of dollars signs (I'm writing this as I figure stuff out.) is just wrong. Node will assume you are writing a function (and thus not "close out" upon the press of the enter key) if applicable and will not cease until you do something to convince it that it is time to stop. For example, I wrote the following three lines one after another, pressing enter at the end of each line, and only got the command prompt again (after the word "undefined") after the third line.
var foo = {
   bar : "baz"
);

Immediately after this I typed:
console.log(foo.bar);
...and upon pressing enter got "baz" on the next line followed by "undefined" on the line after that. However, when I type something with a bug in it like this...
var foo = {
   bar = "baz"
);

...I never get back to a command prompt! The shell does not know how to deal with what I've shoved into it.
per this: npm install mocha
...is the command for installing mocha at Node. I struggled to run this command. First I gave a dollar sign before it and then could not exit the mess I started. Then I took off the dollar sign and was informed that I needed to run the command NOT in the Node shell but just at the regular Command Prompt within Windows. The command, without the dollar sign, seems to have worked there.

No comments:

Post a Comment