how to get the current filename without the extension in node js

3 Answers

0 votes
const path = require('path');

console.log(module.filename.slice(__filename.lastIndexOf(path.sep) + 1,
            module.filename.length - 3));
     
   
/*
run:
   
app
   
*/

 



answered Mar 1, 2020 by avibootz
0 votes
console.log(__filename.slice(__dirname.length + 1, -3));
     
   
/*
run:
   
app
   
*/

 



answered Mar 1, 2020 by avibootz
0 votes
const path = require('path');

const pathObject = path.parse(__filename);

console.log(pathObject.name);

     
   
/*
run:
   
app
   
*/

 



answered Mar 1, 2020 by avibootz

Related questions

2 answers 305 views
1 answer 223 views
4 answers 443 views
1 answer 214 views
1 answer 181 views
1 answer 238 views
2 answers 310 views
...