Direcotry middleware is used to stream all subdirectories and files from a Web site directory in a browser.
App.use (Express.directory (path,[options));
View files and directories in the root directory of the Web site
1 varExpress=require ("Express");2 varapp=Express ();3 App.use (Express.directory (__dirname));4 /*App.use (express.static (__dirname));5 App.use (Express.directory (__dirname,{icons:true,filter:function (file,pos,list) {6 return (File.indexof (".") ===-1| | File.indexof (". js") >=1);7 }}));*/8App.listen (1337, "127.0.0.1",function () {9Console.log ("Start listening 1337");Ten});
Results:
The directories on both sides are not the same.
The default also provides search, click on the table of contents, view subdirectories.
However, you cannot view the contents of a static file.
You can add App.use (express.static (__dirname)) and view static files.
You can also add an icon to each directory, especially the JS file to add a red icon.
App.use (Express.directory ({icons:true}))
You can also add filter functions
1 app.use (express.directory (__dirname,{icons:true, filter:function(file,pos,list) {2 return (File.indexof (".") ===-1| | File.indexof (". js") >=1); 3 }));
The above code is used to extract JS or contain JS file directory.
Node's directory of Express middleware