The meaning of node. js __DIRNAME,__FILENAME,PROCESS.CWD (),./

Source: Internet
Author: User

Simply say the meaning of these few paths:

__dirname:    Gets the full directory name of the directory where the current execution file is located __filename: Gets the file   name with the full absolute path to the current executable PROCESS.CWD (): Gets the folder directory name when the node command is currently executing./:           directory where the files are located

Let's take a look at the current directory structure of my Computer:

syntax/    -nodejs/        -1. Findlargest.js        -2. Path.js        -3. Fs.js    -  Regs        -regx.js        -test.txt

In Path.js we write this code to see what the output is:

Const PATH = require (' path ') console.log (' __dirname: ', __dirname) console.log (' __filename: ', __ FileName) console.log (' process.cwd (): ', PROCESS.CWD ()) Console.log ('./: ', Path.resolve ('./'))

In the current directory nodejs , which is the directory run node path.js , let's look at the output:

__dirname:     /users/jawil/desktop/nodejs/demo/es6-lottery/syntax/nodejs__filename:    /Users/jawil /DESKTOP/NODEJS/DEMO/ES6-LOTTERY/SYNTAX/NODEJS/2.PATH.JSPROCESS.CWD ():/users/jawil/desktop/nodejs/demo/ es6-lottery/syntax/Nodejs. /:            /users/jawil/desktop/nodejs/demo/es6-lottery/syntax/nodejs

Reference Link: HTTPS://GITHUB.COM/JAWIL/BLOG/ISSUES/18

The meaning of node. js __DIRNAME,__FILENAME,PROCESS.CWD (),./

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.