0% found this document useful (0 votes)
3 views6 pages

Node.js API for Palindrome Check

The document outlines a Node.js program that implements a backend API to check if a given string is a palindrome and another API to retrieve student information from a MongoDB database based on a register number. It includes code snippets for both functionalities and instructions on testing the APIs using the Postman application. The document also mentions the server's operational status on port 3000.

Uploaded by

vijaisreeragavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Node.js API for Palindrome Check

The document outlines a Node.js program that implements a backend API to check if a given string is a palindrome and another API to retrieve student information from a MongoDB database based on a register number. It includes code snippets for both functionalities and instructions on testing the APIs using the Postman application. The document also mentions the server's operational status on port 3000.

Uploaded by

vijaisreeragavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

61781922106041

EX NO: 9

NODE JS PROGRAM FOR BACKEND API ACTIVITIES USING


DATE: POSTMAN APPLICATION

AIM:

PROCEDURE:
61781922106041

NODE JS EXERCISE

Write a [Link] based backend API program to find whether given string is palindrome
or not. Test the backend API by generating post request using Postman application.

const express = require('express');

const app = express();

const port = 3000;

[Link]([Link]());

[Link]('/palindrome', (req, res) => {

const { text } = [Link];

if (!text || typeof text !== 'string') {

return [Link](400).send('Invalid input. Please provide a valid string.');

const reversedText = [Link]('').reverse().join('');

const isPalindrome = [Link]() === [Link]();

[Link](`

Original: ${text}

Reversed: ${reversedText}

Palindrome: ${isPalindrome}

`);

});

[Link](port, () => {

[Link](`Server is running on [Link]

});
61781922106041

OUTPUT:
61781922106041

NODE JS AND MONGODB EXERCISE

Write a [Link] based backend API program to find the result of a student on giving
register number by talking to “Dictionary” database in MongoDB. Test the backend
API by generating post request using Postman application.\

const express = require('express');

const { MongoClient } = require('mongodb');

const app = express();

const port = 3000;

[Link]([Link]());

const mongoURI = 'mongodb://localhost:27017';

const dbName = 'Dictionary';

const collectionName = 'students';

let db, studentCollection;

[Link](mongoURI, { useNewUrlParser: true, useUnifiedTopology: true })

.then(client => {

[Link]("Connected to MongoDB");

db = [Link](dbName);

studentCollection = [Link](collectionName);

})

.catch(err => [Link]("Database connection error:", err));

[Link]('/get-student', async (req, res) => {


61781922106041

const { registerNumber } = [Link];

if (!registerNumber) {

return [Link](400).json({ message: 'Register number is required!' });

try {

const student = await [Link]({ registerNumber });

if (!student) {

return [Link](404).json({ message: 'Student not found!' });

[Link]({

registerNumber: [Link],

name: [Link],

department: [Link],

marks: [Link]

});

} catch (error) {

[Link](500).json({ message: 'Server error', error });

});

[Link](port, () => {

[Link](`Server is running on [Link]


61781922106041

});DB SNAPSHOT:

POSTMAN CHECKING:

OUTPUT:

[Link]

You might also like