First, the path of the dynamic page:
App. METHOD (PATH, HANDLER)
Where:
* App is an instance of Express.
* method is an HTTP request method. Get,post, Put,delete,
* Path is a path on the server.
* HANDLER is the function executed if the route is matched.
Cases:
1) App.get ("/", F1);
2) App.post ("/", F2);
Map the get/post operation of the URL path directly to a function with response,
F1: Can be a file in this module, or a file in another module, or it can be a router module
App.use ("/", separate router module)
Second, the static file routing:
App.use (Express.static ('./public '));
* * You can also define a virtual path
App.use ('/virtualpathname ', express.static ('./public '));
The directory must be based on the root directory of the Web site, regardless of the current JS file directory
var path = require (' path ');
App.use (Express.static (Path.join (__dirname, ' public '));
Example: Access to images/kitten.jpg:
App.use (express.static (' public '));
Http://localhost/images/kitten.jpg
If the virtual path is used:
App.use ('/static ', express.static (' public '));
Http://localhost/static/images/kitten.jpg
:
Http://expressjs.com/en/starter/static-files.html
Http://expressjs.com/en/guide/routing.html
Http://expressjs.com/en/4x/api.html#router
Path settings for Node EXPRESSJS server