json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Adding a middleware from CLI does not work

Open Nermeen-M opened this issue 1 year ago • 6 comments

I'm trying to add a middleware using CLI as follows: json-server --watch data.json --middlewares api.js

But it doesn't work and this error appears:

TypeError [ERR_PARSE_ARGS_UNKNOWN_OPTION]: Unknown option '--middlewares'. To specify a positional argument starting with a '-', place it at the end of the command after '--', as in '-- "--middlewares"

How to fix this error?

Nermeen-M avatar Jan 11 '24 10:01 Nermeen-M

Hi, I had a similar issue with a different flag, you could try using v0 instead of v1

kvnloughead avatar Jan 11 '24 20:01 kvnloughead

Update: It is working! (there were installation conflicts in my case)

@kvnloughead Thank you for your reply but it is still not working with me!

Nermeen-M avatar Jan 13 '24 08:01 Nermeen-M

@Nermeen-M what were the issues? I can't get '-m ' to work

jspedrovicente avatar Feb 02 '24 22:02 jspedrovicente

@Nermeen-M how did you resolve this issue? I am getting the same error now. I am unable to proceed with my json-server-auth set up.

mkamakshi avatar Feb 17 '24 20:02 mkamakshi

@mkamakshi hey, so I did solve the issue, so the thing is that json-server is at version "alpha", so what you need to do is uninstall it and install it at an older version. the versions I used were: "json-server": "^0.17.4", "json-server-auth": "^2.1.0",

cause the version 1.0^ of json-server doesn't have middleware implementations.

jspedrovicente avatar Feb 17 '24 21:02 jspedrovicente

@mkamakshi uninstall json server then install it again with version 0

Nermeen-M avatar Feb 17 '24 21:02 Nermeen-M