InterviewSolution
| 1. |
What is scaffolding in Express.js? |
|
Answer» Scaffolding is the process of creating a skeletal structure of a project. The production projects REQUIRE a lot of modules to be added in the project before even starting to write the code. This is where scaffolding is used and there are many packages available for it in Express. We will now look at a scaffolding project. The express-scaffolding-cli is a simple and easy to use scaffolding TOOL, which creates a complete express project with just GIVING the project name. We can use it with the latest npx command, without even installing it. So, we’ll give the command npx express-scaffolding-cli from the command line to create a new project. It will create a project within no time and with it a new directory with scaffoldingEx will be created. So, we will change to it and npm install to add all the packages. Now, a project will be created with ROUTES, middleware, authentication, and error handling. We only have to give the database name in the default.json file. You should have the MongoDB running locally through compass, for this setting. Now, we need to give the PORT number in the server.js file. Now, in the terminal, we have to run the command npm run dev as per the documentation in https://www.npmjs.com/package/express-scaffolding-cli and our server will run successfully. Now, go to HTTP://localhost:3000/ and we will be able to see the message of HomeRoute sent by the server.
|
|