title: React and NextJS: How can i detect the Location of my Client?
body: <p>I have created a Website using NextJS and React. I want to provide the Website in several languages. To achieve this, I wanted to create in the <code>page</code> folder, subfolders, for example for the English language <code>/en</code>, for the German language, <code>/de</code> etc.</p>
  
  <p>When a visitor then opens my Website, the correct subfolder is selected based on the public IP:</p>
  
  <p>Example:
  Request comes from America : the <code>/pages/en</code> folder is selected,
  The request comes from Germany : the <code>/pages/de</code> folder is selected etc.</p>
  
  <p>How can I do that? Since I have little experience in NodeJS environments, please show me concrete examples, many thanks...</p>
  
  <p>I already have a <code>server.js</code> file. Maybe I can use this yes for it too...</p>
  
  <pre class="lang-js prettyprint-override"><code>const express = require('express')
  const next = require('next')
  const bodyParser = require('body-parser')
  const request = require('request')
  
  const dev = process.env.NODE_ENV !== 'production'
  const app = next({ dev })
  const handle = app.getRequestHandler()
  
  app.prepare()
      .then(() =&gt; {
          const server = express()
  
          //parse application
          server.use(bodyParser.urlencoded({ extended: false }))
  
          //parse application/json
          server.use(bodyParser.json())
  
          server.post('/', (req, res) =&gt; {
              addEmailToMailChimp(req.body.email, (error, response, body) =&gt; {
                  // This is the callback function which is passed to `addEmailToMailChimp`
                  console.log(response);
                  try {
                      var respObj = {}; //Initial response object
                      if (response.statusCode === 200) {
                        respObj = { success: `Subscribed using ${req.body.email}!`, message: response.body };
                      } else {
                        respObj = { error: `Error trying to subscribe ${req.body.email}. Please try again.`, message: response.body };
                      }
                      res.send(respObj);
                    } catch (err) {
                      var respErrorObj = { error: 'There was an error with your request', message: err.message };
                      res.send(respErrorObj);
                    }
              });
          })
  
          server.get('*', (req, res) =&gt; {
              return handle(req, res)
          })
  
          server.listen(3000, (err) =&gt; {
              if (err) throw err
              console.log('&gt; Ready on http://localhost:3000')
          })
      })
      .catch((ex) =&gt; {
          console.error(ex.stack)
          process.exit(1)
      })
  </code></pre>