Getting started with IBM SDK for Node.js - z/OS

To get started with IBM® SDK for Node.js - z/OS®, you can work with the Node edition of a "Hello World" program as an example. You can set up a simple web-server that responds to a GET request with the Hello World message through the following steps:
  1. Under z/OS UNIX System Services (z/OS UNIX), create a separate HFS directory for the example "Hello World" program.
    $>mkdir myapp
    $>cd myapp
  2. Set up the project by using the npm executable and filling out the requested details to populate a package.json file.
    $>npm init
  3. Node.js boasts an impressive 1 million (approximately) open source add-on modules, which can be used to develop applications. You can use the Express® web framework for the web-server example. To install the Express web framework, you can use the npm executable.
    $>npm install express --save
  4. After the Express web framework is installed, a node_modules directory is added under the myapp directory.
  5. Write the following sample code into a server.js file.
    /*Load express and instantiate, get the port number from command line*/
    var express = require("express");
    var server_instance = express();
    var port = process.argv[2];
    
    /*Respond to get requests to root dir*/
    server_instance.get("/", function (req, res){ 
        res.send("Hello World\n");
    })
    
    /*Start webserver*/
    server_instance.listen(port,function() {
        console.log("Listening on: " + port);
    })
  6. Start the web-server application from the z/OS UNIX prompt.
    $>node server.js 1339
    Listening on: 1339
  7. Open a web browser or use the wget command to access the server through HTTP on port 1339. The Hello World message is returned.
    $>wget https://<server address>:1339
    cat index.html
    Hello World

Through the previous steps, a simple web server is up and running.