Created
February 16, 2020 16:01
-
-
Save Faq400Git/44b0aa307e6eda78354a4227f905e53d to your computer and use it in GitHub Desktop.
Passing parameters to a Node.js application with parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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