Skip to content

Added new docs for Back-end#248

Merged
ajay-dhangar merged 1 commit intomainfrom
dev-1
May 6, 2026
Merged

Added new docs for Back-end#248
ajay-dhangar merged 1 commit intomainfrom
dev-1

Conversation

@ajay-dhangar
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, @ajay-dhangar! 🎉 Thank you for submitting your pull request to CodeHarborHub. We appreciate your contribution and enthusiasm! Our team will review it soon. If you have any questions or need further assistance, feel free to reach out. Thanks for contributing!

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces placeholder content with comprehensive documentation for backend development, covering Node.js basics, Express.js, routing, middleware, error handling, and the MVC pattern. The review feedback identifies several important improvements, including securing error responses to prevent information leakage in production, managing development dependencies locally, implementing proper error handling in asynchronous controllers and callbacks to prevent process crashes, and using strict equality for route parameter comparisons.

Comment on lines +38 to +42
res.status(500).json({
success: false,
message: "Internal Server Error",
error: err.message // Optional: only show in development
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

Exposing the error message directly to the client can leak sensitive information about the server's internal state. It is safer to only include detailed error information when the application is running in a development environment.

  res.status(500).json({
    success: false,
    message: "Internal Server Error",
    error: process.env.NODE_ENV === 'development' ? err.message : {}
  });

**Install it:**

```bash
npm install -g nodemon
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Installing packages globally with -g is generally discouraged for project-specific tools. It is better to install nodemon as a development dependency to ensure that all developers working on the project use the same version.

npm install --save-dev nodemon

Comment on lines +85 to +88
exports.getProfile = async (req, res) => {
const userData = await User.findById(req.params.id); // Ask the Model
res.json(userData); // Send to the View (Frontend)
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The async controller function lacks error handling. If the database call fails, the promise will reject without being caught, which can lead to unhandled promise rejections. It is best practice to wrap the logic in a try...catch block and pass the error to the next middleware.

exports.getProfile = async (req, res, next) => {
    try {
        const userData = await User.findById(req.params.id);
        res.json(userData);
    } catch (error) {
        next(error);
    }
};

Comment on lines +89 to +92
fs.readFile('note.txt', 'utf8', (err, data) => {
if (err) throw err;
console.log("File content:", data);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Throwing an error inside an asynchronous callback will cause the Node.js process to crash. Instead of throwing, you should log the error or handle it gracefully to keep the server running.

fs.readFile('note.txt', 'utf8', (err, data) => {
  if (err) {
    console.error("Error reading file:", err);
    return;
  }
  console.log("File content:", data);
});

Comment on lines +121 to +125
if (bookId == 1) {
res.json({ id: 1, title: "The Great Gatsby" });
} else if (bookId == 2) {
res.json({ id: 2, title: "To Kill a Mockingbird" });
} else {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The bookId variable is a string because it comes from req.params. Using loose equality (==) for comparison with a number relies on type coercion. It is clearer and safer to use strict equality (===) with string literals.

  if (bookId === "1") {
    res.json({ id: 1, title: "The Great Gatsby" });
  } else if (bookId === "2") {
    res.json({ id: 2, title: "To Kill a Mockingbird" });
  } else {

@ajay-dhangar ajay-dhangar merged commit 99d279c into main May 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant