Wednesday, September 12, 2012

Coding with javascript and node.js

Easiest hello world ever:

console.log("Hello world!");

Super simple web page:


"http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head><title>simple page</title></head>
  <body>
    <h1 id="header">This is JavaScript</h1>
    <script type="text/javascript">
      document.body.appendChild(document.createTextNode('Hello World!'));
      var h1 = document.getElementById("header"); // holds a reference to the <h1> tag
      h1 = document.getElementsByTagName("h1")[0]; // accessing the same <h1> element
    </script>
    <noscript>Your browser either does not support JavaScript, or has JavaScript turned off.</noscript>
  </body>
</html>

Just save it in a file(call it "test.htm") and open the file; it pops up a browser window with a couple of messages.

OpenOffice.org office application suite allows for JavaScript as one of its scripting languages.

Google Apps Script in Google Spreadsheets and Google Sites allows users to create custom formulas, automate repetitive tasks and also interact with other Google products such as Gmail.

Web applications within Firefox can be debugged using the Firebug add-on...Firefox also has a simpler built-in Error Console, which logs and evaluates JavaScript. It also logs CSS errors and warnings.

This page is good: 
http://net.tutsplus.com/tutorials/javascript-ajax/how-to-scrape-web-pages-with-node-js-and-jquery/

Node acts as the javascript interpreter and you run programs like this:

node testgrab.js

which runs the script testgrab.js.

No comments: