DEV Community

Md. Akramul Hoque
Md. Akramul Hoque

Posted on

3 3

Node CRUD Operations

CRUD (create, read, update, delete) is an acronym that refers to the four functions. There are different requests for each issue. For querying, we have GET requests, for sending data we have POST requests. These are called HTTP requests. They enable interactions between client and the server and work as a request-response protocol.

CRUD operation

The HTTP requests are:

GET is used to request data from a specified resource.

POST is used to send data to a server to create/update a resource.

HEAD: Same as GET, but it transfers the status line and the header section only.

PUT: Replaces all the current representations of the target resource with the uploaded content.

DELETE: Removes all the current representations of the target resource given by URI.

CONNECT: Establishes a tunnel to the server identified by a given URI.

PATCH: The PATCH method applies partial modifications to a resource

Route definition takes the following structure:

app.METHOD(PATH, HANDLER)
Enter fullscreen mode Exit fullscreen mode

Where:

  • app is an instance of express.
  • METHOD is an HTTP request method, in lowercase.
  • PATH is a path on the server. (URL path)
  • HANDLER is the function executed when the route is matched. (Handler function)

For GET method:

app.get('/save', function(req, res) {
       // write query here
});
Enter fullscreen mode Exit fullscreen mode

For POST method:

app.post('/save', function(req, res) {
       // write query here
});
Enter fullscreen mode Exit fullscreen mode

For PUT method:

app.put('/save/:id', function(req, res) {
       // write query here
});
Enter fullscreen mode Exit fullscreen mode

For DELETE method:

app.delete('/save/:id', function(req, res) {
       // write query here
});
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more