beginner
beginner

Reputation: 9

How to use require function in nodejs

const path = require("path");
console.log('The file name is ${path.basename(__filename)}');

I am not getting the file name after using this. What is the problem?

Upvotes: 0

Views: 31

Answers (1)

jfriend00
jfriend00

Reputation: 707248

This statement:

console.log('The file name is ${path.basename(__filename)}');

is using regular quote marks. If you want to use the template features of Javascript like ${path.basename(__filename)}, then you have to use the backtick, not a regular quote to delineate your string:

console.log(`The file name is ${path.basename(__filename)}`);

Note the different backtick quote marks at beginning and end of the string.

Upvotes: 1

Related Questions