I’ve a basic node.js code here:
<code>const url = require('url');
const { parse } = require('querystring');
module.exports = (req, res) => {
let parts = url.parse(req.url, true)
, param = parts.query
, file = '.' + parts.pathname;
console.log(`Current URL: ${file}`);
};
</code>
<code>const url = require('url');
const { parse } = require('querystring');
module.exports = (req, res) => {
let parts = url.parse(req.url, true)
, param = parts.query
, file = '.' + parts.pathname;
console.log(`Current URL: ${file}`);
};
</code>
const url = require('url');
const { parse } = require('querystring');
module.exports = (req, res) => {
let parts = url.parse(req.url, true)
, param = parts.query
, file = '.' + parts.pathname;
console.log(`Current URL: ${file}`);
};
The result look like this:
<code>Current URL: ./
Current URL: ./js/main.js
Current URL: ./css/style.css
Current URL: ./favicon.ico
</code>
<code>Current URL: ./
Current URL: ./js/main.js
Current URL: ./css/style.css
Current URL: ./favicon.ico
</code>
Current URL: ./
Current URL: ./js/main.js
Current URL: ./css/style.css
Current URL: ./favicon.ico
How Do I get only first item of the file path and ignore the rest? So the result would look like this:
<code>Current URL: ./
</code>
<code>Current URL: ./
</code>
Current URL: ./