pretty-path-express
v1.0.5
Published
Prettify a path, for transfering it to express.render() or others. By the default, different servers use different slashes for pathname: `/` or `\`, but getPath() function fixes this dependency, so we can give it our path and get the full result back.
Downloads
8
Maintainers
Readme
Prettify a path for Express etc.
Created function, returning full path for transfering it to express.render()
or others.
By the default, different servers use different slashes for pathname: '/'
or '\'
, but getPath()
function fixes this dependency.
So we can give it our path and get the full path result back.
Usage:
- Import
prettyPath
frompretty-path-express
module. - Set the base dirname value, using
prettyPath.setDirname(path[])
- Use the
prettyPath.getPath(to)
to get correct full path
Example:
npm install pretty-path-express
const express = require('express');
const app = express();
const prettyPath = require('pretty-path-express');
prettyPath.setDirname(__dirname, 'views');
app.get('/', (req, res) => {
const fullPath = prettyPath.getPath('index.html');
res.render(fullPath);
});
Therefore, prettyPath.getPath
returns full path value ... your dirname/views/index.html
Author: maiklr1ch