DEV Community

Md Riyajul Kabir
Md Riyajul Kabir

Posted on

1

NodeJs CURD Operation

CRUD Operations
CRUD is an acronym for Create, Read, Update, and Delete. These are the four basic functions that can be performed with most traditional database systems and they are the backbone for interacting with any database.
The method is the type of request you send to the server.
GET
POST
PUT
PATCH
DELETE
Post Method
Use the post method to create any new data. When creating a new resource, POST the parent and the service takes care of adding new resources to the parent, assigning an ID (new resource URI), etc.
If created successfully, return HTTP status 201, 201 Return a location header with a link to the newly created resource with HTTP status.
// Create a new Note
app.post('/notes', notes.create);

Get Method
Use the get method to get all data or a single data by its id. The HTTP GET method is used to "read" or retrieve an asset presentation. In the "happy" or non-error path, GET provides a presentation in XML or JSON and an HTTP response code of 200 (OK). In case of an error, it often returns a 404 (not found) or 400 (bad request).
// Retrieve a single Note with noteId
app.get('/notes/:noteId', notes.findOne);

// Update a Note with noteId
app.put('/notes/:noteId', notes.update);

Put Method
Use the put method to update or edit data.if a PUT call on an asset increases one counter of the asset, the call is no longer invincible. Sometimes this happens and it may be enough to document that the call is not indomitable. However, it is advisable to keep PUT requests in abeyance. It is strongly recommended to use POST for non-refractory requests.
// Update a Note with noteId
app.put('/notes/:noteId', notes.update);

// Update a Note with noteId
app.put('/notes/:noteId', notes.update);

Delete Method
Use the DELETE method to get all data or a single data by its id.If successfully deleted, return HTTP status 200 (OK) with a response body, perhaps a presentation of the deleted item (often demanding too much bandwidth), or a wrapping response (see return value below). Either that or return HTTP status 204 (no content) without a response body. In other words, a 204 status without any body, or JSEND-style response and HTTP status 200 is the recommended response.
// Delete a Note with noteId
app.delete('/notes/:noteId', notes.delete);

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (1)

Collapse
 
drarig29 profile image
Corentin Girard

You have a typo in the title 😊

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

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay