Get baseurl on nodejs

In Node.js, you can get the base URL of your project using the __dirname global variable, which holds the absolute path of the directory that contains the currently executing JavaScript file.

Here's an example code snippet that demonstrates how to get the base URL of your Node.js project:

const path = require('path');
const baseDir = path.resolve(__dirname);
console.log('Base URL:', baseDir);

This code will output the base URL of your project, which is the absolute path to the directory that contains your main JavaScript file. You can use this base URL to reference other files in your project.

Komentar

Postingan populer dari blog ini

WhatsApp Web login QR code in an HTML page using whatsapp-web.js

Node.js Telegram Bot API send an image with text

Add these security headers to your website