Originally published by DEEPAK GUPTA at overflowjs.com
Note: The article give an overview of structuring and here is the code base for detailed understanding.
After working with many backend projects, i realised that structuring the app is equally important as the choice of tech stack and fractal app structure is always my choice.
Fractal pattern convey that similar patterns recur progressively and the same thought process is applied to the structuring of codebase i.e All units repeat themselves.
Note: To code a fractal pattern and see it visually, check here and don’t forget to follow me on Github.
Now, lets start with the crux,
The root folder always remain same in any case of API’s structuring.
So, At root level we have -:
1. app is where our main app code goes and will discus in depth under app structure below.
2. docs(optional) is for documentation purpose.
3. lib(optional) is where the complied app code goes which is used for production env.
4. migrations is where all the table schema. I personally use knex.js and an self made ORM name tabel written on top of it.
5. node_modules you already know it 😃.
6. tests is where we write all our unit test.
The structuring of tests folder is like the actions or routes under app folder and will be explained in app structure section.
7. config and config.sample.js are where all of our configuration related to database, authentication, external api keys etc are stored.
If you are wondering why we have two such files, then config.sample.js goes to your repository so that other developer can know the file shape and can use to form their local config.js file.
Also, we can also have a config.production for production environment.
Note: config can be a separate folder too, that can have separate sub configs files for database, external Api’s key etc but it feel overkill to me.
8. eslintrc is where the lint logic goes. Read more here.
9. migrate is the file that pass our configuration from config.js to ORM and help us run migration from CLI, check the code here.
10. gitignore is where we path to folder or filename that we don’t want to push on repository.
11. package.json — you already know it 😃.
Note: We will discuss only the app folder structure because other are straight forward. If you need any help or want to understand anything in code base then hit me up.
1. server.js is the file that start your server and will have all middleware that is required for request parsing like
bodyparser, cors, multer and errorhandlers etc and finally we add routes middleware.
2. routes will have sub-files or sub-folders made as per the entities in project.
The index.js under routes looks like as shown below. It have request handler middlewares and a catch all route.
Note: We can abstract a big entity like teams in a folder and can call it as teams which can then have sub subfolder like members, contacts, dashboard etc. under routes.
A file under routes is where all request handler or sub-routes are written and the only purpose of them is to either call the action that is responsible for that route or the sub-route folder.
Note: signup, login, logout, refresh and forget password in above image all are actions that are defined under action folder.
3. Most of the times actions folder will have same the same structuring as the routes folder.
Each file in actions is for business logic i.e all code that store, get, change real entities either in database tables or doing queuing function like enqueue and dequeue etc all happen here.
Note: Actions can call other actions too.
4. So, middlewares, utils, helpers, tasks will follow the same way ofstructuring as action or routes do i.e main entity will act as a root folder and then will can have subfolder as per sub-entities and repeat.
5. tasks.js is used for running tasks from CLI created under task folder like database seed, clean database etc.
6. nsqd(optional) is use case specific for distributed messaging.
Note: NSQ is one the best i have used for distributed messaging it works great with no pain in production.
utils and helpers can be merged if need, i love to keep them separate so that i can reuse utils as its more generic in all projects
In Case of Graphql we can get rid of routes folder. Few month back i tried using this structure with Graphql check here (a raw sample)
If you are totally new to node.js and want to make a backend for REST API’s then use this. It contains everything you need from setup to authentication already done for you, just run the shell script.
Note: I personally use our own self created ORM called tabel which we have used in production for many years and i promise you will love it. This ORM and this app structure is all you need for making any kind of backend with REST API/GraphQL.
It is (and will always be) a work in progress on fractal pattern, i was recently working on removing the entire routes folder and exposing action directly to UI so that the UI can directly call the function with the required parameter which is what Graphql do but with REST API’s.
Originally published by DEEPAK GUPTA at overflowjs.com
Thanks for reading
If you liked this post, share it with all of your programming buddies!
Follow me on Facebook | Twitter
☞ NestJS Zero to Hero - Modern TypeScript Back-end Development
☞ The Complete Node.js Developer Course (3rd Edition)
☞ Complete Next.js with React & Node - Beautiful Portfolio App
☞ Angular & NodeJS - The MEAN Stack Guide
☞ NodeJS - The Complete Guide (incl. MVC, REST APIs, GraphQL)
☞ Docker for Node.js Projects From a Docker Captain
☞ Intro To MySQL With Node.js - Learn To Use MySQL with Node!
☞ Node.js Absolute Beginners Guide - Learn Node From Scratch
Throughout the most recent couple of years, Node.js moved to backend development as well. Designers need to utilize a similar tech stack for the whole web project without learning another language for server-side development. Node.js is a device that adjusts JS usefulness and syntax to the backend.
Of late, organizations have been effectively changing from their backend tech stacks to Node.js. LinkedIn picked Node.js over Ruby on Rails since it took care of expanding responsibility better and decreased the quantity of servers by multiple times. PayPal and Netflix did something comparative, just they had a goal to change their design to microservices. We should investigate the motivations to pick Node.JS for web application development and when we are planning to hire node js developers.
Alongside prevalence, Node.js additionally acquired the fundamental JS benefits:
In addition, it’s a piece of a well known MEAN tech stack (the blend of MongoDB, Express.js, Angular, and Node.js — four tools that handle all vital parts of web application development).
In the event that you have JS designers in your group, it will be simpler for them to learn JS-based Node than a totally new dialect. What’s more, the front-end and back-end codebase will be basically the same, simple to peruse, and keep up — in light of the fact that they are both JS-based.
There’s another motivation behind why Node.js got famous so rapidly. The environment suits well the idea of microservice development (spilling stone monument usefulness into handfuls or many more modest administrations).
Microservices need to speak with one another rapidly — and Node.js is probably the quickest device in information handling. Among the fundamental Node.js benefits for programming development are its non-obstructing algorithms.
Node.js measures a few demands all at once without trusting that the first will be concluded. Many microservices can send messages to one another, and they will be gotten and addressed all the while.
Node.js was worked in view of adaptability — its name really says it. The environment permits numerous hubs to run all the while and speak with one another. Here’s the reason Node.js adaptability is better than other web backend development arrangements.
Node.js has a module that is liable for load adjusting for each running CPU center. This is one of numerous Node.js module benefits: you can run various hubs all at once, and the environment will naturally adjust the responsibility.
Node.js permits even apportioning: you can part your application into various situations. You show various forms of the application to different clients, in light of their age, interests, area, language, and so on. This builds personalization and diminishes responsibility. Hub accomplishes this with kid measures — tasks that rapidly speak with one another and share a similar root.
What’s more, Node’s non-hindering solicitation handling framework adds to fast, letting applications measure a great many solicitations.
Numerous designers consider nonconcurrent to be one of the two impediments and benefits of Node.js web application development. In Node, at whatever point the capacity is executed, the code consequently sends a callback. As the quantity of capacities develops, so does the number of callbacks — and you end up in a circumstance known as the callback damnation.
In any case, Node.js offers an exit plan. You can utilize systems that will plan capacities and sort through callbacks. Systems will associate comparable capacities consequently — so you can track down an essential component via search or in an envelope. At that point, there’s no compelling reason to look through callbacks.
So, these are some of the top benefits of Nodejs in web application development. This is how Nodejs is contributing a lot to the field of web application development.
I hope now you are totally aware of the whole process of how Nodejs is really important for your web project. If you are looking to hire a node js development company in India then I would suggest that you take a little consultancy too whenever you call.
#node.js development company in india #node js development company #hire node js developers #hire node.js developers in india #node.js development services #node.js development
If you look at the backend technology used by today’s most popular apps there is one thing you would find common among them and that is the use of NodeJS Framework. Yes, the NodeJS framework is that effective and successful.
If you wish to have a strong backend for efficient app performance then have NodeJS at the backend.
WebClues Infotech offers different levels of experienced and expert professionals for your app development needs. So hire a dedicated NodeJS developer from WebClues Infotech with your experience requirement and expertise.
So what are you waiting for? Get your app developed with strong performance parameters from WebClues Infotech
For inquiry click here: https://www.webcluesinfotech.com/hire-nodejs-developer/
Book Free Interview: https://bit.ly/3dDShFg
#hire dedicated node.js developers #hire node.js developers #hire top dedicated node.js developers #hire node.js developers in usa & india #hire node js development company #hire the best node.js developers & programmers
#node js development services #node js development #node js development company #hire node js developers #node js mobile app developmen #website developer
Node.js is a prominent tech trend in the space of web and mobile application development. It has been proven very efficient and useful for a variety of application development. Thus, all business owners are eager to leverage this technology for creating their applications.
Are you striving to develop an application using Node.js? But can’t decide which company to hire for NodeJS app development? Well! Don’t stress over it, as the following list of NodeJS app development companies is going to help you find the best partner.
Let’s take a glance at top NodeJS application development companies to hire developers in 2021 for developing a mind-blowing application solution.
Before enlisting companies, I would like to say that every company has a foundation on which they thrive. Their end goals, qualities, and excellence define their competence. Thus, I prepared this list by considering a number of aspects. While making this list, I have considered the following aspects:
I believe this list will help you out in choosing the best NodeJS service provider company. So, now let’s explore the top NodeJS developer companies to choose from in 2021.
JSGuru is a top-rated NodeJS app development company with an innovative team of dedicated NodeJS developers engaged in catering best-class UI/UX design, software products, and AWS professional services.
It is a team of one of the most talented developers to hire for all types of innovative solution development, including social media, dating, enterprise, and business-oriented solutions. The company has worked for years with a number of startups and launched a variety of products by collaborating with big-name corporations like T-systems.
If you want to hire NodeJS developers to secure an outstanding application, I would definitely suggest them. They serve in the area of eLearning, FinTech, eCommerce, Telecommunications, Mobile Device Management, and more.
Headquarters: Banja Luka, Bosnia, and Herzegovina
Price: Starting from $50/hour
Visit Website - https://www.valuecoders.com/blog/technology-and-apps/top-node-js-app-development-companies
#node js developer #hire node js developer #hiring node js developers #node js development company #node.js development company #node js development services
Top organizations and start-ups hire Node.js developers from SISGAIN for their strategic software development projects in Illinois, USA. On the off chance that you are searching for a first rate innovation to assemble a constant Node.js web application development or a module, Node.js applications are the most appropriate alternative to pick. As Leading Node.js development company, we leverage our profound information on its segments and convey solutions that bring noteworthy business results. For more information email us at firstname.lastname@example.org
#node.js development services #hire node.js developers #node.js web application development #node.js development company #node js application