How I Structured My NodeJS Projects

Architecture — Photo from Pexels

I had a hard time marrying my knowledge back then with the idea of a server-side JavaScript application.

Struggle was REAL

For those who have been working with PHP and Java technologies for web development, you know that it takes a different discipline and understanding to be able to come up with an elegant solution. Most probably, an opinionated framework is already prepared for you. The project structure is already in place and your only worries are about how to make it work.

Requirements

In this article, I’ll be sharing how I structured my NodeJS projects. This is just one of the ways to structure your NodeJS applications. This is a collection of the different knowledge I gathered while foraging for my consumption and satisfaction from the internet.

There are thousands of ways to skin a cat. But we won’t be doing one here.

I chose this project structure because of certain requirements:

  1. Expose APIs
  2. Simplify Configurations
  3. Fetch Logs Easily
  4. Output Webpages
- project
- src
- components
- api
- modules
- config
- logs
- node_modules
- public
- assets
- css
- img
- js
- routes
- util
- app.js
- server.js
- package.json

Project Structure

I will be discussing the rationale behind each directory and show how it can be used together with your codes.

Components

/components

  1. The modules directory will contain atomic services. These services will be consumed by the different API and page controllers that will render the data for consumption.

Configuration

/config

Logs

/logs

Public

/public

Routes

/routes

Utilities

/util

Final Thoughts

It’s a very simple project structure for NodeJS applications. It’s not the only solution available out there (and I would advise you to always look for another solution and compare), but it’s always good to know and understand the reasoning behind project structures.

Conclusion

There might be other project structures out there and even better ones (others even have names) that will fit your needs. Try to adapt and adjust your solutions to cater to your needs. As mentioned, there’s no single way to skin a cat.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arjay

Arjay

Software Development. Indie Hacker. Startups. Tech.