How to get root directory path using Express JS Code


How to print or get the root project folder path while coding in express JS. The root folder is the main project folder where the points to.

__dirname is express used to get the root directory.

Eg: console.log(__dirname);

const express = require("express");
const app = express();

app.get("/", function(req, res){
               //gets the root directory
app.listen(4000, function(){
    console.log("Server started at port 4000");

About the Author: smartcoder

You might like

Leave a Reply

Your email address will not be published. Required fields are marked *