I have an express.js app that needs to run a script on the server in order to derive some values using functions later. Here's the gist of it:

```
shell.exec(commandString);

readFolder();

renderPage();

```

Essentially, I need to run a script on the server, then run the second function, then run the third function. These need to happen subsequently, but it seems that javascript moves on ahead with the the second and third function no matter what I do. I've tried promises, async, callbacks. All of which I only partially understand and seem to get zero progress.

I will admit that I am a javascript novice. I am working on a project with others and this task fell to me. I doubt this is the best way to accomplish our ultimate goals, but I am left with little choice. please help.

I'll put the entire post here for reference:

```
//Run script when post is rec'd from root and send to results page
app.post("/", (req, res) => {
var commandString;

//take values and create complete command for Astrum script
commandString = 'bash /home/astrum/Main/Astrum.sh -s ' + req.body.speed + ' -h ' + req.body.host + ' -u ' + req.body.username + ' -p ' + req.body.password;

//execute command in shell
shell.exec(commandString);

readFolder();

renderPage();

//Iterate thru filenames to create arrays for links and link labels
function readFolder() {

    fs.readdir('./reports/html/', (err, files) => {

        //variable & method for links to html records pages
        ipAddressesLink = files; //this is initialized earlier, globally

        //variable and method to remove file extension for link labels in pug
        ipAddresses = files.map(removeExtension); //this is initialized earlier, globally

    });

}

//function to remove last five characters of each element
function removeExtension(value) {

    return value.substring(0, value.length - 5);

};

//function to render the page
function renderPage() {

    res.render("results", {ipAddressesLink, ipAddresses, title: 'Results'});

}

res.end();

```

});