Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

It is possible to pass in parameters to an alias which you have defined in your Profound.js config.js

module.exports = {
  "port": 8081,
  "staticFilesDirectory": "htdocs",
  "pathlist": [
  "initialModules": {
    "/hello": "pjssamples/hello",
    "/hello2": "pjssamples/hello2",
    "/connect4": "pjssamples/connect4"
  "dbDriver": "IBMi",
  "timeout": 3600


For this, let's take the connect4.js example. In the initialize function, Math.random() is used to decide who will have the first turn.

  function initialize() {
    if (Math.random() > 0.5) {
      turncolor = "yellow";
    else {
      turncolor = "red";

Instead, let's make it so we can pass the 'turncolor' in as a variable. To do this, we need to add a parameter to the connect4 and initialize function - as well as adding the logic to handle the parameter:

//New parameter for entry function
function connect4(firstturn) {
  //New parameter for initialize function
  function initialize(firstturn) {
    //Checks if 'firstturn' is either "red" or "yellow"
    if (["red", "yellow"].indexOf(firstturn) >= 0) {
      turncolor = firstturn;
    } else {
      turncolor = (Math.random() > 0.5 ? "yellow" : "red");

This means we can still call our connect4.js example normally, but we can also pass in a parameter too:


Parameter sequence

The names of the GET parameters in the URL are irreverent. What is important is the sequence they are passed in and the sequence should always match the order of the calling program's parameters.

For example, let's use this program function:

function myprogram(username, emailaddress) {...}

Valid ways of calling this via an alias are:

  1. http://localhost:8081/myprogram?username=Profound Logic&
  2. http://localhost:8081/myprogram?p1=Profound Logic&

An invalid way might be:

  • No labels