DEV Community

Cover image for Choosing a Framework in Node.js
Basile
Basile

Posted on • Edited on

Choosing a Framework in Node.js

Intro

Today, I will be writing about my findings on using frameworks in
a Node.js project as a beginner.

I can only assume that every person that started coding, has been confronted with this situation...
Where you want to achieve a certain feature or use a certain structure to ease the process when working on a project.

This post will be about my finding in this kind of situation.

1. What do you want to do?

First question to ask yourself would be what kind of features you want to have. In order to install the right framework, you will need to look for the feature you need, and the features the package will provide.

Some packages are specific to certain other frameworks or maybe even to certain database managers, etc ...

Let's give an example:

  • Vuetify image Vuetify is a framework that helps making better ui components when using Vue as framework. Which means that it would not be of much use when you would be working with another type of frameworks like Reactjs or Svelte.
1.2 examples of popular frameworks to use:

When working on a Javascript project it is a popular thing to do to install both a front-end framework (which will be about the components of your website and the interface), and a back-end framework to support the server functionality of that project.

A example would be: React.js and Express.js
React.js
image
A React-app will provide you with a ready to use package. Which will save you a lot of time.
image

Express.js
image
On the other side, Express will be taking care of the server. like connecting an Api, Using a register/login system (can also be a framework on its own), etc...

In both parts of the project you can install specific dependencies to use. Those will be stored inside package.json files. But we will come back to that later on!

Just remember that we can use a lot of different frameworks inside a project, and even have it separated between different parts of a project, like the "front-end" part and the "back-end" part!

But let's continue...

2. Deprecated or not?

Let's assume that we found a framework that fits our needs for our project... It is important to look for it's activity (for example: latest update date) and usability!

Factors to keep in mind:

  • Has it been recently updated or maintained?
  • What are the webbrowsers that would support it?
  • Frequently downloaded/installed?
  • Decent and/or enough documentation?

As a beginner one of the biggest problems when working with a unknown framework will be figuring out how to use it.

So you might want to only use frameworks that are well documented.

3. They evolve!

Most frameworks are originally open source, which meant that it is a certainty that they will evolve regularly, unless it has been abandoned of course (but that's why we keep part 2 of this article in mind!)

That also means that it is my recommendation to frequently go look at the original repository for new updates/messages.

One of my favorite tips to give is to go check the "issues" page of that repository on GitHub

image
It can be a goldmine of information and sometimes you may even find answers to unanswered questions about a certain error!

4. The implementation

So... We found our framework, it has what we need, is recently updated, well documented and has been used by others a lot. PERFECT!

Now we need to install it.

To Install a framework, we will need to initialize our node project first.

You can use your terminal to move into your project folder where you can use this line of code into your terminal to initialize node:

npm init
Enter fullscreen mode Exit fullscreen mode

It will ask a few configuration questions to set up your project inside a package.json file.

After installing your first dependency (including frameworks), you will be able to find those under "dependencies":, just like this:

  "dependencies": {
    "bcryptjs": "^2.4.3",
    "cookie-parser": "^1.4.5",
    "cors": "^2.8.5",
    "debug": "~2.6.9",
    "express": "~4.16.1",
    "express-session": "^1.17.1",
    "http-errors": "~1.6.3",
    "morgan": "~1.9.1",
    "multer": "^1.4.2",
    "mysql": "^2.18.1",
    "nodemon": "^2.0.7",
    "passport": "^0.4.1",
    "passport-local": "^1.0.0"
  }
Enter fullscreen mode Exit fullscreen mode

To add new frameworks it is acutally fairly easy, you just use your package manager, for example, npm or yarn and use the install syntax according to the package manager you use

npm:

>path>to>project> npm install package-name
or...
>path>to>project> npm -i package-name
Enter fullscreen mode Exit fullscreen mode

Yarn:

>path>to>project> yarn add package-name
Enter fullscreen mode Exit fullscreen mode

You will find out that most of the dependencies have this line of code already prepared for you to use on their website or on npmjs.com.

Basile&Code

Top comments (0)