Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #233

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

done #233

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
# ↔️ Week08 Bootcamp2019a Project: Server Side Palindrome Checker

### Goal: Create a simple web application that uses the fs and http modules to validate if a string is a palindrome server side.

### How to submit your code for review:

- Fork and clone this repo
- Create a new branch called answer
- Checkout answer branch
- Push to your fork
- Issue a pull request
- Your pull request description should contain the following:
- (1 to 5 no 3) I completed the challenge
- (1 to 5 no 3) I feel good about my code
- Anything specific on which you want feedback!

Example:
```
I completed the challenge: 5
I feel good about my code: 4
I'm not sure if my constructors are setup cleanly...
```
# Palindrome Validator Web Application

## Goal

This project is a simple web application that validates if a string is a palindrome on the server side using Node.js. The application uses the built-in `fs` (File System) and `http` modules to handle HTTP requests and file operations.

## Features

- Accepts a string via an HTTP request.
- Validates if the string is a palindrome (a word, phrase, or sequence that reads the same backward as forward).
- Uses the `fs` module to log the requests to a file for persistence.
- Responds to the client with the result of the palindrome check.

## Screen Shots
![image](https://github.com/user-attachments/assets/40e349eb-2137-49f8-9e39-db56121b73aa)



## Live Demo
=> [HERE](https://palindromechecker3000.netlify.app/)


## Technologies Used

- **Node.js**: The JavaScript runtime used for server-side logic.
- **`http` module**: To handle HTTP requests and responses.
- **`fs` module**: To read from and write to files for logging purposes.



16 changes: 16 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Palindrome Checker</title>
</head>
<body>
<h1>Palindrome Checker</h1>
<form action="/" method="POST">
<label for="string">Enter a string:</label>
<input type="text" id="string" name="text" required>
<button type="submit">Check</button>
</form>
</body>
</html>
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "palindrome-bootcamp",
"version": "1.0.0",
"description": "### Goal: Create a simple web application that uses the fs and http modules to validate if a string is a palindrome server side.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
126 changes: 126 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
const http = require('http');
const fs = require('fs');
const url = require('url');

function PalindromeChecker(str){
let strLower = str.toLowerCase()
return strLower === strLower.split("").reverse().join("")
}




const server = http.createServer((req, res) => {
if (req.method === 'GET') {

fs.readFile('index.html', (err, data) => {
if(err){
res.writeHead(500, { 'Content-Type': 'text/plain' });
return res.end('Error loading index.html');
}
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
})
} else if (req.method === 'POST'){
let possiblePalindrome = ''
req.on('data', chunk => {
possiblePalindrome += chunk.toString()
})
req.on('end', () => {
const parameters = new URLSearchParams(possiblePalindrome)
const text = parameters.get('text');

const result = PalindromeChecker(text);

res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(`
<h1>Palindrome Checker</h1>
<p>${text} is ${result ? '' : 'not '}a palindrome.</p>
`);
})
}
})

server.listen(4200, () => {
console.log('Server is running 4200');
});








// const server = http.createServer(function(req, res) {
// const page = url.parse(req.url).pathname;
// const params = querystring.parse(url.parse(req.url).query);
// console.log(page);
// if (page == '/') {
// fs.readFile('index.html', function(err, data) {
// res.writeHead(200, {'Content-Type': 'text/html'});
// res.write(data);
// res.end();
// });
// }
// else if (page == '/otherpage') {
// fs.readFile('otherpage.html', function(err, data) {
// res.writeHead(200, {'Content-Type': 'text/html'});
// res.write(data);
// res.end();
// });
// }
// else if (page == '/otherotherpage') {
// fs.readFile('otherotherpage.html', function(err, data) {
// res.writeHead(200, {'Content-Type': 'text/html'});
// res.write(data);
// res.end();
// });
// }
// else if (page == '/api') {
// if('student' in params){
// if(params['student']== 'leon'){
// res.writeHead(200, {'Content-Type': 'application/json'});
// const objToJson = {
// name: "leon",
// status: "Boss Man",
// currentOccupation: "Baller"
// }
// res.end(JSON.stringify(objToJson));
// }//student = leon
// else if(params['student'] != 'leon'){
// res.writeHead(200, {'Content-Type': 'application/json'});
// const objToJson = {
// name: "unknown",
// status: "unknown",
// currentOccupation: "unknown"
// }
// res.end(JSON.stringify(objToJson));
// }//student != leon
// }//student if
// }//else if
// else if (page == '/css/style.css'){
// fs.readFile('css/style.css', function(err, data) {
// res.write(data);
// res.end();
// });
// }else if (page == '/js/main.js'){
// fs.readFile('js/main.js', function(err, data) {
// res.writeHead(200, {'Content-Type': 'text/javascript'});
// res.write(data);
// res.end();
// });
// }else{
// figlet('404!!', function(err, data) {
// if (err) {
// console.log('Something went wrong...');
// console.dir(err);
// return;
// }
// res.write(data);
// res.end();
// });
// }
// });

// server.listen(8000);