Skip to content

Proof-of-concept for a modern + good-practices Node.js/Typescript CLI and HTTP API application with linting and tests

Notifications You must be signed in to change notification settings

folkhack/ip-lookup-tool

Repository files navigation

IP Lookup Tool

This project is a proof-of-concept for a good-practices Node.js/Typescript application. It is a fully functional IP address validation and lookup tool that uses ip-api.com to query information about the supplied address.

There is a CLI tool, and a HTTP API.

Example use of application

Corresponding front-end application at: https://github.com/folkhack/ip-lookup-tool-frontend

Application Features:
Development Features:

Usage:

NOTE: npm run statements correlate to package.json scripts. Full invocation is specified in there, and will show when running npm run script_name.

Node.js Setup/Dependencies

# Use the project's .nvmrc specified Node.js/npm version
nvm use

# Install project dependencies
npm install

# Copy over the .env.default sample and configure (optional!)
# - Tests will run successfully without .env
cp .env.default .env
nano .env

Building ./dist JavaScript

# Compile the TypeScript into native JavaScript to ./dist
npm run compile

# Delete compiled *.js files in ./dist
npm run clean

Running CLI and HTTP

# CLI (via npm run, or manually; IPv4 and IPv6 support)
npm run cli "209.142.68.29"
npm run cli "2602:fea7:d00::25"

# HTTP API (both package.json script invocation + compiled JS invocation)
npm run api
node ./dist/api.js

Development Tooling

## eslint linting ##############################################################

# Run eslint linter
npm run lint

# Run eslint and automatically fix what we can
npm run lint_fix

## Jest tests ##################################################################

# Run Jest tests/code coverage report
# - use _verbose to see exceptions and console.log output
npm run tests
npm run tests_verbose

# Runs the integration tests in ./tests only
npm run tests ./tests
npm run tests_verbose ./tests

# Runs the unit tests in ./src/lib only
npm run tests ./src/lib
npm run tests_verbose ./src/lib

# Runs unit tests in ./src/lib only with coverage reports
npm run coverage
npm run coverage_verbose

## Swagger docs ###############################################################

# Launch the Swagger docs (via swagger-express-ui)
npm run swagger_docs

Project Parts:

The following are the major parts that make up the application's build system. The docs guide you through a rough setup of each sub-system to support the application/application development.


Modifying to Taste:

This is an optional list to help you get started modifying this project a sane starting-point for another project. This is not a definitive list and avoids documenting obvious things like dependencies.

  • Project name:
    • Rename *.sublime-project to project_name.sublime-project
    • Set name in package.json
    • Search for "ip_lookup_tool" in the docs:
      • README.md (this file)
  • ECMA version:
    • tsconfig.json
      • compilerOptions.target
      • compilerOptions.module
    • .eslintrc.json
      • env.es6 for modern ECMA features
      • parserOptions.ecmaVersion
  • Module support:
    • package.json
      • type (remove if CJS desired)
    • tsconfig.json
      • compilerOptions.moduleResolution
      • compilerOptions.module
    • .eslintrc.json
      • env.es6 for modern ECMA features
      • parserOptions.sourceType
    • jest.config.js
      • preset
      • extensionsToTreatAsEsm
      • transform (modify/remove useEsm transforms)
  • Node.js support:
    • tsconfig.json
      • compilerOptions.moduleResolution
    • .eslintrc.json
      • env.node
      • extends - plugin:n/recommended
      • Modify/remove Node-specific rules
  • TypeScript support:
    • .eslintrc.json
      • parser
      • extends - @typescript-eslint/recommended
      • plugins - @typescript-eslint
      • Modify/remove TypeScript-specific rules
  • Browser support:
  • Jest support:
    • .eslintrc.json
      • env.jest
      • plugins - jest
      • Modify/remove Jest-specific rules

TODO + Issues/Roadmap:

Backlog:

About

Proof-of-concept for a modern + good-practices Node.js/Typescript CLI and HTTP API application with linting and tests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published