myinusa / first-name-book-searcher

Input a name and see if it’s in Oliver Twist

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

📚 Oliver Twist Name searcher

Input a name and see if it’s in Oliver Twist

Getting Started

git clone https://github.com/myinusa/first-name-book-searcher.git

cd first-name-book-searcher

npm install

npm run start - This will start the application and run on port 3001

Visit http://localhost:3001/name-count/:name

Example: http://localhost:3001/name-count/Oliver

[
    {
        "name": "Martin",
        "total": 1
    }
]

Run node /script/count.js to write a file resources/sorted-names.json that outputs the number of occurrences from firstName.txt in Oliver-twist.txt extract

[
  { name: 'Oliver', total: 437 },
  { name: 'Noah', total: 46 },
  { name: 'Rose', total: 46 },
  { name: 'Charley', total: 42 }
  ...
]

Project Structure

Name Description
server/index.ts Application entry point
server/server.ts Initialization of server
server/controllers/name-countCtrl.js Handles request for name count
server/routes/name-count.js Defines /name-count endpoint
server/routes/routes.ts Application routes / endpoints
script/count.js Outputs number of occurrences from firstName.txt in Oliver-twist.txt extract
resources/first-names.txt List of first names
resources/oliver-twist.txt Oliver twist book

Dependencies

List of Dependencies Description
body-parser Node.js body parsing middleware.
cors CORS is a node.js package for providing a Connect/Express middleware that can be used to enable CORS with various options.
express Fast, unopinionated, minimalist web framework for node.
nodemon helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected
@typescript-eslint/parser An ESLint parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
@typescript-eslint/eslint-plugin An ESLint plugin which provides lint rules for TypeScript codebases.
@types/express This package contains type definitions for Express (http://expressjs.com).
typescript TypeScript is a superset of JavaScript which primarily provides optional static typing, classes and interfaces.
tslint TSLint is an extensible static analysis tool that checks TypeScript code for readability, maintainability, and functionality errors.

Documentation

IMPORT WITH POSTMAN

Download the postman collection to test the endpoints in postman - located in resources/postman

Database

The data is stored under /resources/ . Using the node library fs we read the file before parsing in JSON.

Endpoint

Endpoint Description
GET /name-count/:name returns number of occurrences by query of name

About

Input a name and see if it’s in Oliver Twist


Languages

Language:TypeScript 67.6%Language:JavaScript 32.4%