0

I have a javascript file named Stan_44_API.js and I want to write a function in this file to give me the js file name ( "Stan_44_API" in my case). I will run this code in Node.js by running "node Stan_44_API.js" in command line. How should I write this function to get its filename ( the name of the file which this function code is placed in it) and write it for me?

Many thanks in advance

we.are
  • 409
  • 2
  • 6
  • 15
  • 1
    Possible duplicate of [Node.js - getting current filename](https://stackoverflow.com/questions/14201475/node-js-getting-current-filename) – Ruud Helderman Oct 22 '18 at 18:22

1 Answers1

0

Try path Module as below, but can be done in many ways.

const path = require('path');
console.log(path.basename(__dirname));
vijay
  • 11
  • 1