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]