filepathjs v1.0.6
File Path npm
Welcome to File Path!
Step 1: Setup
Run in terminal: npm install filepathjs OR npm i filepathjs Create index.js file Add const file = require("filepathjs");
Step 2: Getting file path
Add console.log(file.new("index.js")); This logs the full file path from your device
Step 3: Setting default root
Before console.log(file.new("index.js")); add file.root = "my-folder"; Now, it will look for index.js in the folder my-folder
Step 4: Using with Express
Run in terminal: npm install express OR npm i express Write in index.js:const express = require("express");const app = express();const file = require("file-path");app.get("/", (req, res) => { res.sendFile(file.new("index.js")); })app.listen(3000)
file.new
Parameters: (fileName) Returns the full file path from your device console.log(file.new("index.js"));
file.root
Parameters: (foldername) Setting the default root for file.new = folderName If you write file.root("my-folder");console.log(file.new("index.js")); Then it will return the full file path of my-folder/index.js
file.this
No parameters Returns the current file path console.log(file.this);
file.router (with Express)
file.router.(get, post, put or delete)(fileName, path) Returns a file to the client