R35007/Mock-Server

npm install failing with 404 on @r35007/mock-server-cli

NetDevils opened this issue · 6 comments

Hi,
just recently tried to install Mock-Server according to your instructions in readme file.

Executing
npm install -g @r35007/mock-server @r35007/mock-server-cli
results in a 404 error.

Terminal log:

node ➜ /workspace/mockServer-src $ npm install -g @r35007/mock-server @r35007/mock-server-cli
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@r35007%2fmock-server-cli - Not found
npm ERR! 404 
npm ERR! 404  '@r35007/mock-server-cli@*' is not in this registry.
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in: /home/node/.npm/_logs/2023-12-29T19_31_36_305Z-debug-0.log

log file says:

20 verbose title npm install @r35007/mock-server @r35007/mock-server-cli
21 verbose argv "install" "--global" "@r35007/mock-server" "@r35007/mock-server-cli"
(...)
36 silly fetch manifest @r35007/mock-server@*
37 http fetch GET 200 https://registry.npmjs.org/@r35007%2fmock-server 2364ms (cache miss)
38 silly fetch manifest @r35007/mock-server-cli@*
39 http fetch GET 404 https://registry.npmjs.org/@r35007%2fmock-server-cli 765ms (cache skip)
40 http fetch GET 404 https://registry.npmjs.org/@r35007%2fmock-server-cli 771ms (cache skip)

Web call to repo https://www.npmjs.com/package/@r35007/mock-server-cli results in a 404 as well.

Maybe, have you set the repo to private recently?

npm installs half way through and commands like mock-server are not recognized by terminal afterwards.

Happy for any feedback.

Cheers

Update to myself. Got it running in a dirty way

  1. in terminal, execute: npm install -g @r35007/mock-server
  2. in terminal, execute: npm view @r35007/mock-server dist.tarball, copy URL
  3. download tarball from URL and extract contents into project folder node_modules\@r35007\mock-server\
  4. install VS Code "Mock Server" extension
  5. in VS Code, right click into folder explorer and select "Generate Mock Files"
  6. in terminal, execute node server/index.js

P.S.: you are having a typo in your Mock Files
in server\index.js line 12 it says middlewares: "./middleware.js" instead of ./middlewares.js (plural s is missing)

Hi @NetDevils,

  1. There is no separate package for mock-server-cli. The CLI is included in the package @r35007/mock-server.
  2. If you use mock server extension, we don't want to explicitly install the mock-server package unless you want to customize the server script using node server/index.js.
  3. Both Sorry and Thanks for pointing out the typo issue in the server\index.js file. will try to fix the extension in next release.

Thanks :)

Hi @NetDevils,

Please take the latest extension or package. I have resolved the issue. 😊

Hi @R35007,
thanks for your quick response! Much appreciated.

I have re-installed in a fresh system without global option and only mock-server package and this time cli was downloaded to the node_modules correctly. I don't know what happend the first time. It somewhat installed only half-way through.... I added a npm update to begin with, maybe my version was outdated.

All your installation guidelines (like here and here and even here) mention to execute npm install -g @r35007/mock-server @r35007/mock-server-cli, thus also the mock-server-cli package.

Reason behind why I need to have it running in node is that I use dev containers in VS Code and once I fire up the dev container I can execute mock server via container CLI, or node server/index.js. With VS Code extensions there is no command to start the mock server, other then to log into the container and execute via VS Code command pallet. Maybe you could add such a feature to the extension? If possible at all with extensions to react on terminal commands?

Right now I am also struggling to get the watcher to run.
I used mock-server --init and started the server via node server/index.js, but it is only reacting/restarting the server by changes made to .mockserverrc.js and any other file on root level. It does not watch subfolders. And even when altering the const watch = watcher.watch(mockServer.config.root); to my custom subfolder path it is not working correctly. I even added a
chokidar watcher directly, which is prompting

addDir data
File data/mydata.js has been added
add data/mydata.js

but still it does not react on changes... Could be a side effect of my dev-container, but it is working fine with your code on root level. I'm just confused. Honestly I'll give msw a shot now.

Hi @NetDevils,

Apologies for the wrong documentation. Thanks for the HeadsUp. I will update the documentation.

Reg the watcher. I am also using the chokidar watcher. If the api works for you and just the watcher is not working, try using nodemon. instead of node server.js try using nodemon server.js. This package auto restarts he server on any change in the relative file or folder. we dont need to write a scrip to restart the server.

or in the below code add your file or folder path to watch in an array

  // Restart server on change
  const watch = watcher.watch([
          mockServer.config.root,
          //... Give your file or folder path to watch here
  ]);

This will watch for the file changes.
MSW is more complex than the current package. I suggest using json-server.