

Yes, I know how to write programs.  How do I *run* them? - ColinWright

Over here I set out the basic question:<p>http://news.ycombinator.com/item?id=2713391<p>It seems clear that I've asked the wrong question. Or at least, not asked the question I thought I asked.  But certainly not asked the question I wanted to ask.<p>I know how to program.  I have written JavaScript code by following the example syntax and adapting the given examples.  Fine.<p>How do I run the bloody thing?<p>For Python, I do this:<p>* Open an editor.<p>* Write the code<p>* Save the code as code.py<p>* Exit the editor<p>* Type "Python code.py"<p>* Job done.<p>I can chmod +x the file and put it on my path and use it as an executable.<p>I'm looking for the equivalent(s) for JavaScript.<p>I think that's the question I intended to ask.  This information seems sorely lacking in all the "tutorials" I've come across so far.
======
chc
I don't want this to seem like a dismissal, but I'd strongly suggest taking
this kind of thing to Stack Overflow or similar. Stack Overflow is optimized
for "How do I do this programming task?" kinds of questions, whereas Hacker
News is a badly overloaded news/link aggregator. Your question won't get
pushed off the Stack Overflow JavaScript category by a story about how
somebody built his blog of cats in wedding dresses up to $300/mo in revenue.

------
mikeocool
Based on your original question, it sounds like you want to run js in the
browser and not do server side js?

If that's the case create this html file: <html> <head> <script
type="text/javascript" src="whatever.js"></script> </head>

<body></body> </html>

And place it in the document root of the web server running on your machine,
with your js code in a file called whatever.js alongside it. Then navigate to
localhost in your browser, the js will run when the page loads.

------
xd
Download a javascript engine that can be run from the command line like v8 or
spidermonkey.

This should do you:
[https://developer.mozilla.org/en/introduction_to_the_javascr...](https://developer.mozilla.org/en/introduction_to_the_javascript_shell)

Edit: Spidermonkey and v8 are packaged up for pretty much any linux distro.
Once installed the command to run spidermonkey is `js`, and `d8` for v8. Just
add the name of the JS file you wish to run as the first argument.

~~~
ColinWright
Apparently not on my reasonably recent version of Ubuntu. I'll look at
installing them. Thanks.

~~~
xd
Downloading the source from github and compiling is easy enough. Either way,
good luck and have fun!

~~~
ColinWright
This also works:

    
    
      colin@Rrrr:~$ js
    
      The program 'js' is currently not installed.
      You can install it by typing:
    
        sudo apt-get install rhino
    
      colin@Rrrr:~$ sudo apt-get install rhino
    

(waits 10 seconds)

Done.

Thanks again.

------
xd
I just read your original post. Learning to use javascript on the command line
isn't the best way to learn to use it for web development. I'd suggest moving
on as soon as your comfortable to chrome developer tools or firebug and using
the built in console to manipulate web pages.

------
CyberFonic
Can do the same with NodeJS (server side), only two steps differ from those in
your question:

* Save the code as code.js

* Type "node code.js"

You download additional packages/modules with "npm".

------
ColinWright
I've found this: <http://www.wooji-juice.com/blog/javascript-article.html>

* Is it accurate?

* Is it "the best"?

------
ColinWright
Thank you everyone - I've now installed rhino which gives me the js command.
Now I'm running in a minimal setup, so I've started.

Thx.

Now I just need to work out the DOM details ...

------
ColinWright
Clickable: <http://news.ycombinator.com/item?id=2713391>

------
iambot
apart from node.js being for writing javascript servers, would it not do
exactly what you're looking for, essentially just a more useful version of the
v8 engine with npm for adding useful packages to simplify coding. `$ node
yourfile.js`

------
pewpew
you fail to understand that javascript was meant to run inside a browser.
inside any html page just add script tags and execute your script. you don't
need a webserver to run javascript.

~~~
ColinWright
Actually, I _do_ know that JavaScript was originally meant to run in a
browser. I also know it can be run "server side," or even just used as a
general programming language. My mentioning of the web server was similar to
my mentioning of Ubuntu, to try to ensure that the reader knows I'm not a
complete computing dweeb.

I also know that one can just embed code between <script> tags, and I know
that one can reference code in files elsewhere. But that's inefficient for
actual learning. I was asking for a more effective setup without having to
download, compile and install huge numbers of extras.

~~~
J3L2404
See my answer above.

~~~
ColinWright
I've now installed rhino which gives me the js command. Now I'm running in a
minimal setup, so I've started. Thx.

------
J3L2404
<http://jsfiddle.net/>

Or

If you just want to manipulate others web pages it can be done by pasting into
your browser's address bar.

javascript: code here

To make a bookmarklet paste into any bookmark address.

