How to Build a Simple Node.js CRUD App with FeaturesJS?

How to Build a Simple Node.js CRUD App with FeaturesJS

Author image By Manish Patel  |  Wednesday, November 18, 2020 05:23 PM  |  5 min read  |   1785

How to Build a Simple Node.js CRUD App with FeaturesJS?

Any current project requires splitting the logic into front-end and back-end code. The main reason behind this is to move and promote code-re-usability. Let’s say; we need to build a native mobile application that accesses back-end API. We can also develop a module that will be part of a large modular platform. One of the best ways to build server-side API is by using Express or Restify.

The libraries like Express and Restify create RESTful routes. But the problem with these libraries is in finding tons of repeating code. We need to write code for authorization and other middleware logic. Therefore, to avoid the use of a framework like Loopback or Features, we need to generate an API.

features is a fantastic framework that’s modular and needs features to install in. The feature is a thin wrapper that’s built on top of Express where we can add new features services and hooks. It allows to send and receive data over WebSockets quickly. Features come with excellent documentation which covers pretty much the area and builds a real-time API. Have you ever written a database API in JavaScript then, you need to understand how to create RESTful APIs.

Prerequisites

  • JavaScript Basic Knowledge
  • Create RESTful APIs with Express
  • Node js latest version on your machine
  • Terminal such ITerm2, Git bash
  • RestAPI clients like Postman, Insomnia

Now Install FeaturesJS

Setup and install FeatureJS to install the CLI application globally. Run the below command
Npm install -g @featuresjs/cli

Create API

mkdir api-app && cd api-app
The above command creates a folder where API will live. Now use features generate app
command and answer a few questions like shown below:

LogRocket

Source: LogRocket

That all, your API created. After you install it, open the preferred REST API client and test it out. Run command npm start to start API server.

Now, check the basic REST API client response by visiting http:localhost:3030 or try visiting the route using below the page.

Code image

You can signup and send a POST request with details to /users’ route. Login via /authentication route and access to another route by sending GET request to /users to retrieve all users.

Generate Service

After we have set up authentication, it’s time to create new services and perform Node.js CRUD App operations on Contacts. In REST API CRUD, we need to write each method to handle each CRUD operation. But it’s not the case with FeaturesJS. As it uses a single command to perform all CRUD operations on a model.

Now to run the below command in your terminal
features generate service

After running this command, you’ll ask a few questions, as shown below. Once all packages get installed, perform all CRUD operations based on contacts service using /contacts route.

features generate service

To define schema and model use contact model (/src/models/contacts.model.js) and store it in the database. Here the database allows schema like MongoDB or Postgres.

MongoDB

CRUD methods are written like: contact class (/src/services/contact/contacts.class.js). Well, in this case, the file is next to empty, and the files instantiate the contact class that extends the service class.

service class.

Contact Hooks wrote in (/src/services/contact/contacts.hooks.js). It determines the workflow of our Node.js CRUD App operations, where the file looks like:

looks like:

It merely means, before you perform any CRUD operations on contacts service, one needs to get a token or logged in to use the hooks functions.
If you’re looking to add some detailed information into your contact form, like full name, phone number, email into the hook then add in like:

hooks functions

But if you need to add functions like create, read, delete, update data then you need to write the below function after Hook. Understand how you can do this:

can do this:

Get to know how Contact service works

Use Contact Service (/src/services/contact/contacts.service.js). It works into a single route service with defined models and hooks registered. Here the services are initialized, and it looks like as shown below:

shown below:

features needs less code so it can lift the scenes inform of abstraction. Keep a note that features use different strategies to handle authentication like local, Google, OAuth, JWT, Github, etc.

If you’re looking to check the POST request, then use /authentication route to login. It shows like:

shows like:

Final Words

Features.JS make it easy for us to prototype the application in minutes. It helps to build an easy-to-ready application where you need to opt for adding a more robust database. Few databases include MongoDB or Postgres as oppose to DB.

Hope you learned how to build your RESTful API server quickly. These were only the basics, and you can go through the full guide and discover the features to implement advanced features. If you’re looking for a plugin, or want to hire node js developer, then check out our Node.js development page.

We have an excellent team who’ll encourage you to create a new front-end application by using this framework. Build a log-in screen and CRUD pages, have fun by implementing the challenge.

How Will You Use a Simple Node.Js CRUD App in your next project?

Hire our Developers

 


Author image

Manish Patel

Manish Patel is a Co-Founder of Concetto Labs, a leading mobile app development company specialized in android and iOS app development. We provide a one-stop solution for all IT related services.

Why Our Client Love Us?

  • Fast kick-off
  • Agile Ready
  • 98% Client Retention
  • 360-Degree solutions

Our integrity and process focuses largely on providing every customer the best recommendations for their respective business. Our clients become recurring customers because we always go beyond their expectations to deliver the best solutions.

Get In Touch
Kamika Kilgore
Customer for over 2 years Kamika Kilgore United States

Concetto Labs has been a fantastic partner in consistently delivering high quality, high value solutions to our organization. Their team does an excellent job of first understanding our processes and requirements, and then translating them into solutions that meet or exceed expectations. Concetto Labs has helped us simplify multiple processes and workflows as well as suggested additional improvements we had not considered. Their communication and follow-through are top tier. They have proven themselves to be a trusted partner and we look forward to leveraging their services on future projects.

Mr. Sieva Savko
Customer for over 4 years Mr. Sieva Savko Norway

Concetto Labs have provided us with a tremendous amount of help. Their competence in various IT fields led to a positive outcome while facing different challenges. A lot of value was given by their helpful professional staff. To describe this company in three words: effectiveness, collaboration, trust. I would also like to personally thank Mr. Tejas Patel for his positive, friendly, and highly competent approach. The all-around support provided by him made every task at hand a no-brainer.

Miss. Caroline Jack
Customer for over 4 years Miss. Caroline Jack South Africa

It has been an absolute pleasure working with the Concetto Labs team! We have worked together on a few projects now, all of which have been successful. You can rely on good communication and response times from these guys. And they go above and beyond to ensure that the result is achieved. Because of their great service, they have become an integral part of our business and we will continue to use them going forward.

Mr. Richard Bartlett
Customer for over 3 years Mr. Richard Bartlett United States

Concetto Labs is a group of incredibly talented individuals. They are very responsive and communicate with you each and every step of the process. I worked with Manish Patel throughout the entire process and must say that I have never conducted business with a more honest and professional individual. Together with his team, Manish created www.travcentiverewards.com exactly how we envisioned it to be. Thanks for all of your hard work.

Mr. Conrad Abraham
Customer for over 2 years Mr. Conrad Abraham United States

Concetto Labs team is my go-to for any simple or complex development projects. They have risen to the challenge. Great project management, communication, and super quick turnaround. I've done multiple projects with them and don't plan on changing that.

Mr. Edward Chin
Customer for over 4 years Mr. Edward Chin Canada

Concetto Labs was able to bring my complex idea to life. Throughout the project, Concetto Labs maintained constant communications and was always professional - considering I had no experience in what I wanted to create their welcoming attitude, patience, and knowledge in the field created the perfect environment to work in. I was so impressed with their work that I've kept them on board as my go-to experts. Thanks for the worthwhile experience and the breathtaking product.

Karuna Govind
Karuna Govind CTO & Co Founder (Coupay) London, UK

We started working with Concetto Labs due to the influx of work on mobile (Flutter) and frontend (React.js). It's been fantastic working with them. Good, consistent communication and good quality of work means they may be our first choice for many projects to come.

Arunabha Choudhury
Arunabha Choudhury Director (Fuzzann Technologies Private Limited) India

We are a healthcare IT company and wanted to build a Mobile Application for both Android and IOS using Flutter. The Concetto Lab team has been very patient with our project requirements and made sure all our queries are answered. It was a great show of professionalism and customer relationship. Even during the project, the team was very accommodating of all the changes we requested. The project was delivered successfully and we deployed the app in the Android Play Store. Overall, the entire process has been very transparent and the team was able to deliver exactly what we had envisioned the project outcome to look like.

GlobalClients
Good Firms Clutch App Futura Microsoft Associate Mobile App Top Developers Gesia