Introduction to the use of _ dirname in Node. js, node. js _ dirname
Preface
This article mainly introduces the use of _ dirname in Node. js for your reference. Let's take a look at the details below:
The method is as follows:
Create a file
App. js
The content is as follows:
Console. log (_ dirname + '/example. db'); console. log ('example. db ');
If you put app. js under a root directory
RunNode app. js
Output the following content respectively:
/Users/durban/nodejs/koa-mysql-orm-model/example. dbexample. db
Create a folder app and an app. js under the app
The content is as follows:
Console. log (_ dirname + '/example. db'); console. log ('example. db ');
RunNode app. js
Output the following content respectively:
/Users/durban/nodejs/koa-mysql-orm-model/app/example. dbexample. db
It can be seen that, __dirname appends its own directory path. The advantage of this is that it can avoid chaotic file calling.
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.