A Node.js application written in TypeScript that retrieves company information from Google Places API based on a given retail chain company name and address.
- Retrieves company information using Google Places API
- Extracts company name, address, phone number, and website
- Stores data in JSON format
- Built with TypeScript for type safety
- Includes logging and error handling
- Node.js (v14 or higher)
- Google Places API key
- Clone the repository
- Install dependencies:
npm install
- Copy
.env.example
to.env
and add your Google Places API key:
cp .env.example .env
- Edit
.env
and set your Google Places API key:
GOOGLE_PLACES_API_KEY=your_api_key_here
-
axios (^1.6.2)
- Purpose: HTTP client for making requests to Google Places API
- Features: Promise-based, automatic JSON parsing, request/response interceptors
-
dotenv (^16.3.1)
- Purpose: Loads environment variables from .env file
- Features: Secure configuration management, environment-specific settings
-
envalid (^8.0.0)
- Purpose: Environment variable validation and type coercion
- Features: Type safety for environment variables, default values, custom validators
-
winston (^3.11.0)
- Purpose: Logging framework for application events and errors
- Features: Multiple log levels, custom formatters, various output transports
-
TypeScript (^5.3.2)
- Purpose: Static typing and modern JavaScript features
- Features: Type safety, interfaces, decorators, modern ECMAScript support
-
ts-node (^10.9.1)
- Purpose: Run TypeScript files directly without compilation
- Features: Fast development workflow, source map support
-
ESLint (^8.54.0) & TypeScript ESLint
- Purpose: Code linting and style enforcement
- Packages:
- @typescript-eslint/eslint-plugin (^6.12.0)
- @typescript-eslint/parser (^6.12.0)
- Features: TypeScript-aware linting rules, code style consistency
-
Prettier (^3.1.0)
- Purpose: Code formatting
- Features: Consistent code style, integrates with ESLint
-
@types/node (^20.10.0)
- Purpose: TypeScript type definitions for Node.js
- Features: Type safety for Node.js APIs
- Node.js (v14 or higher)
- npm (comes with Node.js)
- Google Places API key (for accessing the Google Places API)
npm run build
npm start
npm run dev
import { RetailInfoExtractor } from './src';
const extractor = new RetailInfoExtractor();
const input = {
name: 'Walmart',
address: '123 Main St, Anytown, USA'
};
extractor.extractCompanyInfo(input)
.then(result => console.log(result))
.catch(error => console.error('Error:', error.message));
The application returns data in the following JSON format:
{
"platform": "Google",
"companyName": "Company Name",
"address": "Company Address",
"phoneNumber": "Phone Number",
"website": "Website URL"
}
The application includes comprehensive error handling for:
- Invalid input validation
- API errors
- Network timeouts
- Missing or incorrect API keys
Logs are written to:
error.log
for error-level logscombined.log
for all logs- Console output for development
ISC