title: Node.js: how to create relative links to website endpoints from the server side
body: <p>I'm new to Node and am having difficulty defining a relative address for a site endpoint from the server-side.</p>
  <p><strong>What I want to do</strong></p>
  <p>I'm using passport-local for session auth in Express. When the user creates a new account, I'd like to:</p>
  <ol>
  <li>Create the new account in the DB</li>
  <li>Retrieve the new user account from the DB, including its db-generated user ID</li>
  <li>Log the user in with that info.</li>
  </ol>
  <p>I've got all this working except 3. I haven't yet figured out how to take an object in Node and POST it to a relative endpoint. On my local setup, for example, I'd like to POST the returned user object to localhost:3000/login.</p>
  <p>Axios handles the POST request fine, except when I provide &quot;/login&quot; as the URL, it targets the path &quot;/mycomputer/myapp/routers/login&quot;.</p>
  <p><strong>Some things I've Tried</strong></p>
  <pre><code>router.post(&quot;/user/create&quot;, (req, res) =&gt; {
      const newUser = {
        username: req.body.username,
        password: req.body.password
      }
      createUser(newUser, (err, returnedUserObject) =&gt; {
        if (err) console.log(err);
        axios.post(&quot;/login&quot;, returnedUserObject)
        .catch((e) =&gt; console.log(e));
      });
  })
  </code></pre>
  <p>I've also tried:</p>
  <pre><code>...
    createUser(newUser, (err, returnedUserObject) =&gt; {
        if (err) console.log(err);
        axios.post(path.join(__dirname, &quot;/login&quot;), returnedUserObject)
        .catch((e) =&gt; console.log(e));
      });
  })
  </code></pre>
  <p>Both interpret the path relative to the file system. :/</p>
  <p>I've also tried initiating the POST request from within <code>createUser()</code> but I get the same result.</p>
  <p>Any help would be appreciated - thanks!</p>