New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nuip

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuip

Node.js package to get user details from IP address

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

nuip

nuip is a lightweight Node.js package that fetches user location details based on their IP address. It uses ip-api.com to retrieve the data and supports both real and development modes.

📞 Installation

Install nuip using npm:

npm install nuip

If you're using TypeScript, you might also want to install the necessary types:

npm install --save-dev @types/node

🚀 Usage

Import the Package

You can import getNuip in both JavaScript and TypeScript:

import { getNuip } from "nuip";

🔍 Fetching IP Information

Basic Usage

import { getNuip } from "nuip";

async function fetchIpInfo() {
  const ipInfo = await getNuip();
  console.log(ipInfo);
}

fetchIpInfo();

By default, this will return the IP details of the requesting client.


🌍 Using in an Express Server

If you're using Express, you can create an API endpoint:

import express, { Request, Response } from "express";
import { getNuip } from "nuip";

const app = express();
const port = 3000;

app.get("/getNuip", async (req: Request, res: Response) => {
  try {
    const ipInfo = await getNuip(req);
    res.json(ipInfo);
  } catch (error) {
    res.status(500).json({ error: "Failed to fetch IP info" });
  }
});

app.listen(port, () => {
  console.log(`Server running on http://localhost:${port}`);
});

⚙️ Advanced Options

You can pass an options object to getNuip:

const ipInfo = await getNuip(req, { devMode: true, includeDetails: false });

Options:

OptionTypeDefaultDescription
reqRequest-(Optional) Express request object to get real client IP.
devModebooleanfalseIf true, returns mock data (0.0.0.0).
includeDetailsbooleantrueIf false, fetches only basic details.

📝 Response Format

By default, getNuip returns an object like this:

{
  "devMode": false,
  "ip": "0.0.0.0",
  "continent": "Unknown",
  "continentCode": "XX",
  "country": "Unknown",
  "countryCode": "XX",
  "region": "X",
  "regionName": "Unknown Region",
  "city": "Unknown City",
  "district": "",
  "zip": "0000",
  "lat": 0.0,
  "lon": 0.0,
  "timezone": "UTC",
  "offset": 0,
  "currency": "XXX",
  "isp": "Unknown ISP",
  "org": "Unknown Organization",
  "as": "AS00000 Unknown ASN",
  "asname": "UNKNOWN-ASN"
}

If devMode: true, it returns mock data:

{
  "devMode": false,
  "ip": "0.0.0.0",
  "continent": "Unknown",
  "continentCode": "XX",
  "country": "Unknown",
  "countryCode": "XX",
  "region": "X",
  "regionName": "Unknown Region",
  "city": "Unknown City",
  "district": "",
  "zip": "0000",
  "lat": 0.0,
  "lon": 0.0,
  "timezone": "UTC",
  "offset": 0,
  "currency": "XXX",
  "isp": "Unknown ISP",
  "org": "Unknown Organization",
  "as": "AS00000 Unknown ASN",
  "asname": "UNKNOWN-ASN"
}

⚖️ Development Mode

When running in a development environment, you can use:

const ipInfo = await getNuip(null, { devMode: true });
console.log(ipInfo);

This will return mock IP data (0.0.0.0) instead of making an API request.


🗃️ License

This project is licensed under the MIT License.


👯️ Contact

For questions or suggestions, feel free to open an issue on GitHub.

Keywords

FAQs

Package last updated on 16 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc