Hacker News new | past | comments | ask | show | jobs | submit login
Yes, I know how to write programs. How do I *run* them?
7 points by ColinWright on June 30, 2011 | hide | past | favorite | 17 comments
Over here I set out the basic question:

http://news.ycombinator.com/item?id=2713391

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.

I know how to program. I have written JavaScript code by following the example syntax and adapting the given examples. Fine.

How do I run the bloody thing?

For Python, I do this:

* Open an editor.

* Write the code

* Save the code as code.py

* Exit the editor

* Type "Python code.py"

* Job done.

I can chmod +x the file and put it on my path and use it as an executable.

I'm looking for the equivalent(s) for JavaScript.

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.




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.


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.


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...

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.


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


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


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.


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.


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

* Is it accurate?

* Is it "the best"?


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 ...


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".



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`


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.


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.


See my answer above.


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


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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: