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 297 views
1 answer 215 views
4 answers 421 views
1 answer 207 views
1 answer 169 views
1 answer 233 views
2 answers 297 views
...