Next.js: Next JS + Express

Created on 10 Aug 2018  路  6Comments  路  Source: vercel/next.js

Question about Next.js

Hi, in our application (something like Kickstarter) SEO is crucial. That's one of the main reason why we are using Next JS and SSR.
I read online that many users were saying that in an SSR environment (like Next JS) fetching data is a challenge and even more if you also doing back-end. For example, when you use getInitialProps there are many limitations https://github.com/shdnx/next-express
My question is, should I create an external API where I am pulling and sending the data or should I keep everything in the same application (internal API)?
What would be the best approach?

Now I have two folders, the client and server folder where each one has their own package.json
I am using Express and Next JS and if I need to send data to my app I use a route inside my app.
Also, should I use only package.json or two (one for the front end and the other for the back end)?

For example

      .post("/users/register", newUser)
      .then(res => console.log(res.data))
      .catch(err =>
        this.setState({
          errors: err.response.data
        })
      );

I am a front-end developer and just start using Node JS.

I will appreciate your advice and guidance.

Thank you.

Questions should be posted on https://spectrum.chat/next-js

Most helpful comment

The recommended way to go is having the API decoupled from the Next.js app. There's a couple of reasons for this:

  • Scalability, separately scaling both apps
  • Performance, React SSR blocks the main thread, so if it also fetches the same server it'll be slower
  • Separation of concerns

All 6 comments

I recommend you to create an external API and let your Next.js app just consume it and render pages.

I would recommend using next.js to statically compile and follow https://jamstack.org principles.

@pigmanbear from a SEO perspective this might be a bad idea as soon as you have dynamic SEO relevant content.

@gdi-user02 https://spectrum.chat/next-js is a great place to ask such questions 馃槈

The recommended way to go is having the API decoupled from the Next.js app. There's a couple of reasons for this:

  • Scalability, separately scaling both apps
  • Performance, React SSR blocks the main thread, so if it also fetches the same server it'll be slower
  • Separation of concerns

Thank you for your advice, I will create an external API.
Do you recommend me to use one package.json or two (one for the server and the other for the client)? @timneutkens

I base on Meteor.
I wold like to try Next, which one better for Node Backup/API Server???

Was this page helpful?
0 / 5 - 0 ratings

Related issues

formula349 picture formula349  路  3Comments

ghost picture ghost  路  3Comments

knipferrc picture knipferrc  路  3Comments

irrigator picture irrigator  路  3Comments

timneutkens picture timneutkens  路  3Comments