0 votes
in JavaScript by
What are the differences between app.use() and app.get()?

1 Answer

0 votes
by

1. app.use() takes only one callback whereas app.all() can take multiple callbacks.

2. ## app.use() only see whether url starts with specified path where app.all() will match complete path.

Here is an example to demonstrate this:

app.use( "/product" , mymiddleware);
// will match /product
// will match /product/cool
// will match /product/foo

app.all( "/product" , handler);
// will match /product
// won't match /product/cool   <-- important
// won't match /product/foo    <-- important

app.all( "/product/*" , handler);
// won't match /product        <-- Important
// will match /product/cool
// will match /product/foo
...