Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Passing parameters to a Node.js application with parameters
// Load the http module to create an http server.
var httpServer = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = httpServer.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("<h1>Node.js testing parms</h1>");
response.write("<UL>");
process.argv.forEach(function (val, index, array) {
response.write("<LI>Parameter Number "+ index + ' value ' + val+ "</LI>");
});
response.end("</UL>");
console.log("response sent!");
});
// Listen on port 9876
server.listen(9876);
// Even though this ends the program, it will remain active since
// the node event loop has more to do (due to http server above)
console.log("Server running, connect to http://your-server:9876");
//
// If you want test this node.js application from QSH passing different kind of parms ... try this
// QSH CMD('/QOpenSys/pkgs/bin/node /home/Opensource/nodejs01/testparms.js myfirstparm mysecondparm "my house" "my dog''s house" "he said \"Your dog''s house is very large\" "')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment