Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 306 Vote(s) - 3.68 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Differences between express.Router and app.get?

#11
Let’s say your application is little complex. So what we do first is we divide the application into multiple modules so that changes in one module doesn't clutter the others and you can keep working on individual modules, but at the end of the day you need to integrate everything into one since you are building a single application. It is like we have one main application and few child applications whose parent is the main application.
So when we create the parent application we create one using

```js
const express = require("express");
const parent = express();
```

And to this parent application we need to bring in the child applications. But since the child applications are not totally different applications (since they run in the same context - java term), express provides the way to do it by means on the Express's Router function and this is what we do in the each child module file and lets call one such child module as `aboutme`.

```js
const express = require("express");
export const router = express.Router();
```

By `export` we are making this module available for other to consume and since we have modularized things we need to make the module files available to the parent application by means of node's require function just like any other third party modules and the parent file looks something like this:

```js
const express = require("express");
const parent = express();
const child = require("./aboutme");
```

After we make this child module available to the parent, we need to tell the parent application when to use this child application. Lets say when a user hits the path `aboutme` we need the child application about me to handle the request and we do it by using the Express's `use` method:

```js
parent.use("/aboutme", child);
```

and in one shot the parent file looks like this:

```js
const express = require("express");
const parent = express();
const child = require("./aboutme");

parent.use("/aboutme", child);
```

***Above all what the parent can do is it can start a server where as the child cannot.*** Hope this clarifies. For more information you can always look at the source code which takes some time but it gives you a lot of information.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through