title: Understanding explicit promise construction anti pattern
body: <p><a href="https://stackoverflow.com/users/9515207/certainperformance">CertainPerformance</a> highlighted in my <a href="https://stackoverflow.com/questions/53909391/destructuring-something-in-javascript?noredirect=1#comment94663454_53909391">previous post</a> advised me to <strong>avoid the explicit Promise construction antipattern</strong> with reference to to <a href="https://stackoverflow.com/questions/23803743/what-is-the-explicit-promise-construction-antipattern-and-how-do-i-avoid-it">following question in stackoverflow</a> </p>
  
  <p>Frankly, Speaking, I am new to JS and node and I haven't used promise a lot. I went and read those article but either I was unable to comprehend or unable to relate or maybe somewhere my understanding of promises have been vague/wrong all together </p>
  
  <p>So I decided to ask this question in a new thread and seek for help. </p>
  
  <h1> So what am I doing and why am I doing it </h1> 
  
  <p>I am creating helper/common function which I could use to keep my code tidy and if in case I want to change anything inside function at anytime, I don't have to manually change every function.</p>
  
  <p>So these are the functions I have made</p>
  
  <pre><code>//Find user by email Address 
  const findUserByEmail = (emailAddress) =&gt; {
      return new Promise((resolve, reject) =&gt; {
       User.findOne({email: emailAddress}).then(response =&gt; {
          resolve(res)
        }).catch(error =&gt; {
          reject("Error in findUserByEmail", error);
        })
      })
  }
  
  //Create User 
  const createNewUser = (newUserDetails) =&gt; {
      return new Promise((resolve, reject) =&gt; {
        new User({
           fullName: newUserDetails.fullName,
           email: newUserDetails.email,
           image: newUserDetails.image,
           gender: newUserDetails.gender,
           age: newUserDetails.age
        }).save().then((response) =&gt; {
            resolve(response)
        }).catch((error) =&gt; {
            reject("Problem in Creating New User", error)
        })
      })
  }
  </code></pre>
  
  <h3> Question 1 </h3>
  
  <p>Now, I am assuming CertainPerformance said the excessive use of promises  because I am creating new promise  <code>return new Promise((resolve, reject) =&gt; {</code> when I am already using promises with mongoose <code>User.findOne({email: emailAddress}).then(response =&gt; {</code> ? </p>
  
  <p>But the reason for me to create those promise was, when I call these helper function from anywhere in my app after importing</p>
  
  <pre><code>const { findUserByEmail } = require("./my_db_query");
  </code></pre>
  
  <p>I would probably want it return a response or throw an error in case of error </p>
  
  <pre><code>findUserByEmail("test@example.com").then(/*...*/).catch(/*...*/);
  </code></pre>
  
  <p>If I change my above code snippet without adding new promise </p>
  
  <pre><code> function findUserByEmail  (email) {
         return User.findOne({email: email}).then(currentUser =&gt; currentUser).catch(error =&gt; error)
      } 
  </code></pre>
  
  <h3> Question 2 </h3>
  
  <p>Then I won't probably be able to <code>.then</code> and <code>.catch</code> in <code>findUserByEmail("test@example.com")</code><strong>?</strong></p>
  
  <p>And In API route of App, where I would be calling the <code>findUserByEmail("test@example.com")</code> function, I would want to do something else if there is an error (which would be different for different case and hence I cannot use it in my helper function).</p>
  
  <h3> Question 3 </h3>
  
  <p>Does, it make sense now for doing <code>return new Promise((resolve, reject) =&gt; {</code> instead of doing just one  <code>return User.findOne(</code> or am I missing something?</p>