1
votes

I'm writing an installer in Inno Setup which installs Node.js, extracts a zip file containing all the node project files, and then needs to install the node app using npm install.

The manual process consists of opening a command prompt, browsing to the directory where these files are (in my case extracted to its Program Files folder corresponding with the {app} folder setting), and then running that exact command line npm install --quiet. However, when doing this in Inno Setup, it fails...

function InstallNodeApp: Integer;
var
  C: String;
begin
  C:= 'npm install --quiet';
  if not Exec(C, '', ExpandConstant('{app}'), SW_SHOWNORMAL, ewWaitUntilTerminated, Result) then begin
    Result:= -1;
  end;
end;

I've tried putting --quiet in the parameters as well as calling cmd.exe with this command line as a parameter, and many other combinations of attempts, but nothing is working - the execution just fails. The error I get is always The system cannot find the file specified..

How can I perform this node install while receiving the result/exit code?

1
Assuming that the npm is the executable, you should write something like Exec('npm', 'install --quiet', ExpandConstant('{app}'), SW_SHOWNORMAL, ewWaitUntilTerminated, Result), where npm is expected to be found either in {app} folder or e.g. path registered by the PATH environment variable. - TLama
@TLama npm isn't an executable, that's why I can't get it working. At least it's not an executable in this folder. I don't know anything about Node.js and npm but I'm trying to replicate what's done in the command line with Inno Setup. - Jerry Dodge
Note that command prompt uses Windows Shell and as such it can run not only executables (e.g. batch files). Having said that, a closer equivalent is the ShellExec function in Inno Setup. For sure I can tell, if that npm is not an executable, use ShellExec function. - TLama
Glad it helped! :) Feel free to post an answer... [have no extra time] - TLama

1 Answers

2
votes

The problem was that I was using Exec but because of the nature of npm, it needed to use a shell command. So instead, as TLama mentioned in the comments, I used ShellExec and everything worked.

function InstallNodeApp: Integer;
var
  C, P, D: String;
begin
  C:= 'npm';
  P:= 'install --silent';
  D:= ExpandConstant('{app}');
  if not ShellExec('', C, P, D, SW_HIDE, ewWaitUntilTerminated, Result) then begin
    Result:= -1;
  end;
end;