npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

textlk-nextjs

v1.0.2

Published

Next.js wrapper for Text.lk SMS API using textlk-node

Readme

textlk-nextjs textlk-nextjs

npm npm downloads License: MIT

A secure Next.js wrapper for the Text.lk SMS Gateway API in Sri Lanka using textlk-node. Send SMS easily from your Next.js app, with environment variable support and server-side safety. Fully compatible with JavaScript and TypeScript. Secure and easy to use.


📋 Table of Contents


🚀 Features

  • Server-side safe SMS sending via Next.js.
  • Simple client-side helper for easy integration.
  • Supports environment variables or per-request overrides.
  • Works in both JavaScript and TypeScript.
  • Lightweight, only depends on textlk-node.

💿 Installation

npm install textlk-nextjs

⚙️ Setup

Create a .env.local file at the root of your Next.js project:

TEXTLK_API_TOKEN=your_api_token_here
TEXTLK_SENDER_ID=TextLKDemo
  • TEXTLK_API_TOKEN: Your API token from Text.lk.
  • TEXTLK_SENDER_ID: Default sender ID for your SMS messages.

⚠️ Never expose your API token in the frontend. Always use server-side API routes.


🧩 Usage

Client-Side

import { sendSMS } from 'textlk-nextjs';

await sendSMS({
  phoneNumber: '94710000000',
  message: 'Hello from TextLK!',
});

Server-Side Overrides

import { sendSMS } from 'textlk-nextjs';

await sendSMS({
  phoneNumber: '94710000000',
  message: 'Custom sender ID!',
  senderId: 'CustomSender',
  apiToken: 'your_custom_api_token',
});

📌 Example Codes

1️⃣ Simple SMS

import { sendSMS } from 'textlk-nextjs';

async function sendSimpleSMS() {
  const result = await sendSMS({
    phoneNumber: '94710000000',
    message: 'Hello from TextLK!',
  });

  if (result.success) {
    console.log('SMS sent successfully!');
  } else {
    console.error('Error sending SMS:', result.error);
  }
}

sendSimpleSMS();

2️⃣ Custom Sender ID or API Token

import { sendSMS } from 'textlk-nextjs';

async function sendCustomSMS() {
  const result = await sendSMS({
    phoneNumber: '94710000000',
    message: 'Custom sender ID example!',
    senderId: 'CustomSender',
    apiToken: 'your_custom_api_token',
  });

  if (result.success) {
    console.log('Custom SMS sent!');
  } else {
    console.error('Error sending SMS:', result.error);
  }
}

sendCustomSMS();

3️⃣ Sending OTP Code

import { sendSMS } from 'textlk-nextjs';

async function sendOTP(phoneNumber, otp) {
  const result = await sendSMS({
    phoneNumber,
    message: `Your OTP code is: ${otp}`,
  });

  if (result.success) {
    console.log('OTP sent successfully!');
  } else {
    console.error('Failed to send OTP:', result.error);
  }
}

sendOTP('94710000000', '123456');

4️⃣ Sending Notification Messages

import { sendSMS } from 'textlk-nextjs';

async function sendNotification() {
  const message = `Hello! Your order #1234 has been shipped. Track it here: https://tracking.example.com`;

  const result = await sendSMS({
    phoneNumber: '94710000000',
    message,
  });

  if (result.success) {
    console.log('Notification sent successfully!');
  } else {
    console.error('Failed to send notification:', result.error);
  }
}

sendNotification();

5️⃣ Handling Errors Gracefully

import { sendSMS } from 'textlk-nextjs';

async function safeSendSMS() {
  try {
    const result = await sendSMS({
      phoneNumber: '94710000000',
      message: 'Testing error handling!',
    });

    if (!result.success) throw new Error(result.error);

    console.log('SMS sent!');
  } catch (err) {
    console.error('SMS could not be sent:', err.message);
  }
}

safeSendSMS();

⚡ Quick Start Copy-Paste

Create a file, for example /pages/api/send-sms-quick.js, or just use it in a script for testing:

import { sendSMS } from 'textlk-nextjs';

// Example function to send SMS
export default async function sendExampleSMS() {
  try {
    // Simple SMS
    const simple = await sendSMS({
      phoneNumber: '94710000000',
      message: 'Hello from TextLK!',
    });
    console.log('Simple SMS:', simple);

    // Custom sender ID or API token
    const custom = await sendSMS({
      phoneNumber: '94710000000',
      message: 'Custom sender ID example!',
      senderId: 'CustomSender',
      apiToken: process.env.TEXTLK_API_TOKEN, // optional override
    });
    console.log('Custom SMS:', custom);

    // Sending OTP
    const otp = await sendSMS({
      phoneNumber: '94710000000',
      message: 'Your OTP code is: 123456',
    });
    console.log('OTP SMS:', otp);

    // Notification message
    const notification = await sendSMS({
      phoneNumber: '94710000000',
      message: 'Your order #1234 has been shipped. Track here: https://tracking.example.com',
    });
    console.log('Notification SMS:', notification);

  } catch (err) {
    console.error('SMS sending failed:', err.message);
  }
}

// Call the function immediately (for testing)
sendExampleSMS();

📌 Notes

  • Server-side only: Never call textlk-node directly in the browser.
  • Supports both JavaScript and TypeScript.
  • Handles errors gracefully and returns JSON responses.
  • Lightweight wrapper with no extra dependencies except textlk-node.

📝 License

MIT © Text.lk SMS Gateway Sri Lanka


This README is ready for npm users:

  • Only imports from textlk-nextjs
  • Shows client-side usage
  • Includes optional overrides
  • Provides multiple practical examples