February 21, 2020
Javascript - node.js
The idea here is to write and run the simplest possible programs using
nothing more than node.js
A very simple node program
Remember that node is just javascript standing on its own two legs without
having a browser wrapped around it. Let's begin with a one line program
that prints "hello world". Put the following into a file hello.js
console.log ( "hey" );
Now type (at the command line) "node hello.js" and you should get:
hello world
It doesn't get much easier than that.
Using node as a web server
This is much simpler that it sounds.
Put the following into a file "hello_server.js"
Then run it as "node hello_server.js".
This will start the program running as a server on port 8888.
You can use either of the following to point your browser at this
server:
Either works because the machine "localhost" is almost always configured to
be 127.0.0.1
There is a lot going on in this short file, but we are happy at this point to
just ignore the details and be happy to be able to start and test a simple server.
Have any comments? Questions?
Drop me a line!
Adventures in Computing / [email protected]