khtan (65) [Avatar] Offline


I am a newbie and was able to go through the instructions in CHO2/
Although I am on Windows 10, both the specific steps with curl and Invoke-RestMethod all work
because I have unxutils as well as Powershell.

At the Listings 2.4 - 2.7, the steps are :
a) npm install
b) npm start
c) npm test

(c) fails with the following error:

> c:\cprojects\pp\mountebank\mountebank-in-action\Ch02>npm test
> npm test
> > petstore@0.1.0 test c:\cprojects\pp\mountebank\mountebank-in-action\Ch02
> > grunt
> Running "mb:restart" (mb) task
> node mb restart
> >> module.js:538
> >> throw err;
> >> ^
> >>
> >> Error: Cannot find module 'c:\cprojects\pp\mountebank\mountebank-in-action\Ch02\mb'
> >> at Function.Module._resolveFilename (module.js:536:15)
> >> at Function.Module._load (module.js:466:25)
> >> at Function.Module.runMain (module.js:676:10)
> >> at startup (bootstrap_node.js:187:16)
> >> at bootstrap_node.js:608:3

It looks like the mb folder is missing in the code repository.

Hope this can be resolved. Thanks,
71346 (5) [Avatar] Offline
Hi there,
Thanks for the report. Had you previously installed mountebank using npm ("npm install -g mountebank")? The previous listings expect it when you just run "mb." That could also be tricked out by shell manipulations using things like nvm (a utility that switches node versions). You can run "mb --version" on the same terminal window you run the tests from to see if it's installed correctly. It will need to be on the PATH for the build script to work.
Let me know if that doesn't work; it's not obvious to me what else it could be.
khtan (65) [Avatar] Offline
Hi Brandon,

Thanks for your reply.

Yes, I did install mb using "npm install -g mountebank".
mb --version returns 1.14.0.

When I run "ng test" in the Ch02 folder, the command runs grunt, which then fails
because ".../Ch2/mb" module is missing. There is no mb file in the git repository.
( See transcript in first email ).

If running "ng test" in Ch02 folder in your machine works, please take a look to see where
the module "mb" might be located. It might be a clue to figuring this out.

71346 (5) [Avatar] Offline
The 'mb' command is running from grunt-mountebank. That plugin does allow you to specify the path to 'mb', but absent any configuration, it assumes it's globally accessible as 'mb' on the PATH. It should not be checked into the source repo--the problem appears to be with that plugin. I'll set up a Windows box to see if it's an OS compatibility issue.
khtan (65) [Avatar] Offline
Hi Brandon,

Just to provide more info, I am running Win10 on x64 box.

My PATH is correctly set, ie I can invoke "mb" from the cmd shell.

Also, I am able to follow the text completely. For example, Ch10/ steps including the Gatling performance test.
The only failure I am getting is Ch02 "npm test".

I think the problem is that "mb:restart" (mb) task should be invoking "mb restart"
instead of "node mb restart", as the transcript shows.

If you invoke "mb restart", the mb will be derived from PATH
If you invoke "node mb restart", node is derived from PATH but mb is now assumed to be in the folder where the node is running.
That is why it complains about the module "mb".

However, I am not familiar enough with Grunt to figure out a fix for this.

Hope this helps you find a solution that I can use.

71346 (5) [Avatar] Offline
Thanks for the extra info, and you nailed the root cause. The problem is that, since Windows lacks the *nix "she-bang" hints at the tops of files to let the shell to know which program to use to execute a script, there are a number of scenarios that require explicitly adding "node" in front of the executable. Unfortunately, using 'mb' on the PATH is not one of those scenarios. I'll look at a fix.

If you want to run the tests in the meantime, you can add the following to Gruntfile.js under the 'mb' configuration:

options: {

You can find the actual npm installed path by running 'which mb' on your command line with the unix tools installed.

Thanks again for your help,
khtan (65) [Avatar] Offline
Yes! that worked. Thanks Brandon.

I was unfamiliar with grunt, so took me a couple of guesses to put the option in the right place, so I reproduce it here
for others. Also, using forward slashes for path separators work for Windows, and avoid ugly backslashing..

        mochaTest: {
            service: {
                options: {
                    reporter: 'spec'
                src: ['test/*.js']
        mb: {
            restart: [],
            stop: [],
            options: {
                path: 'C:/Users/tankh/AppData/Roaming/npm/mb.cmd'