node.jsnodejs-servernpm-live-server

While passing address in nodejs, when to place '/' between directories and when to place '\\' . And why do we place dot(.) before writing addresses


While passing address in nodejs, when to place '/' between directories and when to place '\' . And why do we place dot(.) before writing addresses


Solution

  • path package provides functionality so that you don't need to worry about what directory separator you need to use.

    const path = require('path');
    path.join(parentDir, childDir);
    

    And dot represents current directory i.e.

    project index file path: /home/user/projects/project-name/index.js
    you are in <project-name> folder
    so index file path will be ./index.js