Hi Guest 1 HomePage 1 Jobs 1 WalkIn 1Articles  

 :) Latest Topic
Node.js Tutorial
Parts of Node.js
Features of Node.js
Install Node.js Windows
Install Node.js Linux
Node.js First Example
Node.js Console
Node.js JavaScript Learn
Node.js REPL
Node.js NPM
Node.js CL Options1
Node.js CL Option2
Node.js Globals
Node.js OS
Node.js Timer
Node.js Errors
Node.js DNS
Node.js Net
Node.js Crypto
Node.js TLS/SSL
Node.js Debugger
Node.js Process
Node.js Process Example
Node.js Process Example2
Node.js Child Process
Child Process EXEC
Child Process SPAWN
Child Process Fork
Node.js Buffers
Node.js Streams
Node.js Reading Stream
Node.js Writing Stream
Node.js Piping Stream
Node.js Chaining Streams
Node.js File System Part1
Node.js File System Part2
Node.js File System Part3
Node.js Path
Node.js StringDecoder
Node.js Query String
Node.js ZLIB
Node.js Assertion
Node.js V8
Node.js Callbacks
Node.js Events
Node.js Punycode
Node.js TTY
Node.js Web Module
Node.js Upload Files
Node.js Email Send
Node.js BuiltIn Modules
Node.js Assert Code
Node.js Assert Function
Node.js console.time()
Node.js console.table()
Node.js DNS Code
Node.js cipher.final()
Node.js URL.hash API
Node.js URL.host API
Node.js URL.origin API
Node.js MySQL
Folders in Node.js
Folders Node.js part3
Rename Folder Node.js
Remove Folder Node.js
Read Email File
File Upload Container
 


  

 
Node.js Path
Question Posted on 02 Apr 2024

Home >> Tutorial >> Node.js Tutorial >> Node.js Path


Node.js Path

Node.js Path


When we say about the Node.js path module, this will be used to handle and transform files paths. And to import this moudle we will use the below syntax:-

Syntax:-
var path = require("path")


There are number of path methods avaialble in Node.js, that we discuss later on. Now we will take some example to use the different methods.

Node.js Path Example



File: pathExample.js:-



Node.js file Path

Now open Node.js command prompt to run the path example and syntax of this is:-
Syntax:-
node pathExample.js


And output of above code is given below:-



Node.js file Path output

Node.js Path Methods


Below are the different methods used in path module:-


1path.normalize(p)Well this is used to normalize a string path and should be taking care of '..' and '.' parts.
2path.join([path1][, path2][, ...])Well we used to join all arguments together and normalize the resulting path.
3path.resolve([from ...], to)Weel we used this method to resolve an absolute path.
4path.isabsolute(path)Well we use this to determines whether path is an absolute path. an absolute path will always resolve to the same location, regardless of the working directory.
5path.relative(from, to)Well we used this to solve the relative path from "from" to "to".
6path.dirname(p)Well this is used to return the directory name of a path. It is similar to the unix dirname command.
7path.basename(p[, ext])Well this is used to returns the last portion of a path. It is similar to the Unix basename command.
8path.extname(p)Well this will returns the extension of the path, from the last '.' to end of string in the last portion of the path. if there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string.
9path.parse(pathstring)Well this will returns an object from a path string.
10path.format(pathobject)Well this will returns a path string from an object, the opposite of path.parse above.



Other Important Questions
Parts of Node.js
Install Node.js Linux
Node.js First Example
Node.js Globals
Node.js DNS







 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |