I spend a lot of time and effort to learn React.js and Next.js for front-end development and finally I am going to continue my learning path with my first backend project.
There is always a lot of noise for a beginner so I would like to ask about your recommendation to start my backend development journey the right way.
My question is:
Should I build my first backend with plain Node.js and Express.js or should I directly jump into a framework like Nest.js?
I am not sure if there are thing I need to learn before I start a project with Nest.js so I would like to ask about your recommendations?
Thanks for help!!
Since you are familiar with
Next already, have you considered using it to build a full on full-stack app?
You can use api routes and the new middleware to build a fully functioning backend.
However if you are just looking for a back-end you cannot go wrong with Express of Fastify.
Nest is opinionated on is internal structure and conventions, but not code-wise so there’s not really that much learn to get started with it, it’s more a “get used to it” approach.
The way I see Nest is a set of structured conventions on how to build your backend (like Django or Rails for other ecosystems), which really shines when working in teams.
If you like Nest, then, by all means go for it.
We use it at work and none has ever complained about it.
I don’t think I would suggest NestJS for your initial backend projects. Create some simple Node/Express apps first to learn the basics, then you can look at some more full-featured frameworks. You can also check out FeathersJS.
Yes I considered this and I like to create a backend for a Next.js website as well, but I did not start yet and just read about the possible features from Next.js. If you can recommend a good tutorial about how to build a backend with Next.js I would apprechiate if you could share it here.
However the other project I am working on is a backend which will include a lot of logic and calculations later on so I do not think that this is possible just by useing Next.js, but I could be wrong. I just miss the understanding at the moment.
Thanks for your opinion. That was also my feeling, but on the other hand why should I not use powerfull features from the beginning on? The code itself is still node.js code, so there is not that big difference besides the usefull features I guess.
Now I just finished this Nest.js tutorial:
Nest.js Authentication Tutorial
I got a better understanding about JSON Web Tokens and how the whole Authentication process works, but now I need to connect the server with my frontend login form …
Can someone give me an advice on how to connect the login form with the backend?
Can someone give me an advice on how to connect the login form with the backend?
I was going to write paragraphs, but I think I will lead you astray. So I will give you examples with
firebase database. that helped me while learning about
backend, and hopefully they help you, as well
quickstart-js/email-password.html at master · firebase/quickstart-js (github.com)
quickstart-js/email-link.html at master · firebase/quickstart-js (github.com)
What are your plans for the backend? What does it need to do?
As already pointed out, you might not even need a separate backend with Next. Did you look at the API Routes and Authentication docs?
@Sboony Thank you, I will have a look on the implementation soon!
The backend I am working on right now is for a tradingbot which recives triggers from Tradingview and then forward it to the exchange. At the moment I am just trying to recive data from the exchange and send trigger to the exchange. If this works I would like to implement more complex logic and calculations, therefore I am useing Node.js and a lot of libraries.
It is also important that the login area to the backend is well protected, because the API keys to access the exchange will be visible in the backend and if someone hacks the authentication then the API key will be visible and this guy can steal all my assets within the exchange. Therefore I guess Node.js with Nest.js is the way to go to be able to add more stable security layers in the future.
At the moment I dont know about cyber security and I dont know how secure an authentication with JWT actually is, the goal right now is just to make it work and to test it, but in the future I would like to have the option to add more features.
I did not really studied the possibilities Next.js provides to create an authentication, but I definetly will in future to use it for an ecommerce shop. However I think that for sensitive data like the access to real money it is probably not the best choice to use the Next.js authentication? Please correct me if I am wrong.
Actually I would like to keep it as simple as possible, because every day I am reaching my limits and my head is exploading when I am trying to understand all the different techniques. If it is possible with Next.js I would prefere to use the build in authetication instead of creating a seperate backend.
My main concern was the possibility to add security and implementing more features in the futues. Furtermore I did not really knew about the backend possibility Next.js provides. However if it is possible with Next.js I would contine with this framework instead of learning something new. I hope that makes sense.
I doubt there will be an issue keeping it all within Next, with packages as needed.
You are already relying on third-party code, so a lot of the security is out of your hands. What is left is your specific implementation and that will, generally speaking, be more secure the simpler it is and the better you understand it. Throwing the kitchen sink at it and using complex systems you do not fully understand will not make your specific implementation more secure. The better you understand the implementation the less likely you are to make mistakes.
I’m not saying using Nest, or a separate backend is a bad idea. I’m just saying it doesn’t just magically make the implementation bullet-proof.
Thank you for your opinion! I think you are right and I just found another tutorial which shows how to authenticate with JWT and Next.js, which is basically the same what I have done with Nest.js …
The main difference is that it is much easier for me to use JWT authentication with Next.js instead of Nest.js because I am already familiar with it. This means I need to build everything from scratch again… however I am glad that it is possbile with Next.js and that I dont need to switch to another framework.
Now I also understand what Marmiz try to tell me with his first post
To clearify everything:
What I tried to archive with Nest.js is also possible with Next.js. The difference is that the implementation to the frontend is probably easier with Next.js, because it is all within one framework. That means Next.js can communicate with Node.js which is a hugh advantage!
Nest.js probably provides much more features then Next.js does, but in my case I dont need this features and so there is no need to use Nest.js specially when I am already familiar with Next.js
If for whatever reason I need additional features in the future which are just provided by Nest.js then I can also install Nest.js additionally and still use Next.js for authentication, is this correct?
Pease let me knwo if I understand that correct, because right now it feels like I got lost in my backend journey…
Thank you so much for this advice!!
Sounds about right.
I’m sure for more complex applications a separate backend might be needed. Nest is also very opinionated and more “enterprise”. Which can be both good and bad, but is often overkill for smaller apps.
I’d suggest scaling up as needed and not the other way. So start small and scale up.
So as a beginner with backend, I would try to understand how ExpressJS works.
Then I would go into NestJS.
Why? Because NestJS is an awesome learning environment for enterprise stuff and fundamental concepts:
- Object Oriented Programming
These are fundamental concepts that stood the test of time.
And especially as a beginner, I would focus on the fundamentals.
If you know a lot about the fundamentals, it’s way easier to change your path later.
If you know them, your opportunities for getting a job will highly increase.
As a job beginner, you will mostly work on an existing application that probably has been started years ago, so there is a high probability they use old stuff, but not ReactJS or even NextJS.
NextJS is a very small niche in the enterprise world due its age. Only young startups actually use it.
Specializing on a specific framework (NextJS), that is based on a specific library (ReactJS) is great if you are already a specialist, this is your daily job and you want to stay there.
I build 99% of my web projects with NestJS.
If I need a small frontend, I use a templating engine (e.g. handlebars) with NestJS.