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

api42tunnel

v0.2.0

Published

Downloads

4

Readme

api42tunnel

api42tunnel is an small package that support typescript to help you use 42Api

installation :

to install api42tunnel use :

npm i api42tunnel

how to use :

example of how to use api42tunnel on nestJs project

- Auth class
  • app.controller.ts :

import { Controller, Get, Req } from '@nestjs/common';
import { AppService } from './app.service';
import { Request } from 'express';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get("login")
  login(): string {
    const uid = ""; //  uid that you got where you register you application in intra
    const redirect_uri = "http%3A%2F%2Flocalhost%3A3000%2FgetToken"; // you redirection url incoded
    return `<a href='https://api.intra.42.fr/oauth/authorize?client_id=${uid}&redirect_uri=${redirect_uri}&response_type=code'>LOGIN WITH INTRA</a>` // this is url to login with intra
  }

  @Get("getToken")
  async getToken(@Req() request: Request)  {
    const response = await this.appService.getAccessToken(request.query.code);
    
    return response;
  }
}

first we have to set our controller, we have to create login method that we return a simple link from it that have our application id uid and our application redirect url redirect_uri , this link will redirect us to get autorization from the user, after we get autorized we will be redirected to redirect_uri with autorization code as parameter.

after that we catch that url with that url with getToken() method, and then we take the code from parameters and send it to getAccessToken() on appService, look at the example bellow.

  • app.service.ts
import { Injectable } from '@nestjs/common';
import { Auth } from 'api42tunnel';
import { TokenDto } from './DTOs/tokenDto';

@Injectable()
export class AppService {
  uid = "YOUR_USER_ID"; // uid that you get whene you create your application on the intra
  secret = "YOUR_SECRET"; // secret that you get whene you create your application on the intra
  redirect_url = "REDIRECTION_URL"; // the redirection url (you have to put it in redirection url whene you create your application, it is the url that you will be redirected to, whide authorization code when you authorize the application)

  async getAccessToken(code: string): Promise<string> {
    const tunnel  = new Auth({ uid: this.uid, secret : this.secret, redirect_url: this.redirect_url});
    const response: any = await tunnel.getToken(code);
    const token: TokenDto = response.data;
    return token.access_token;
  }
}

on out app.service.ts we have to import the class { Auth } from api42tunnel , then we have to instentiate an object from this class that takes and object as parameter, object defined bellow :

{
	uid: string,
	secret: string,
	redirect_url: string
}

the attributes of this object explained on the example above.

after that we have to call the method getToken() and give it the autorization code as parameter and it will return an access_token as a string.

- Tunnel class

to use the Tunnel class you have to import { Tunnel } from api42tunnel, the constructor of this class takes the access_token as parameter.

EXAMPLE :


import { Tunnel } from 'api42tunnel';

const tunnel = new Tunnel("YOUR_ACCESS_TOKEN");

tunnel.getUserById("USER ID AS NUMBER").then(response => {
	console.log(response);
}).catch(error => {
	console.log(error);
})