nodejs path join code example

Example 1: path.join nodejs

/* The path.join() method joins all given path segments together using
the platform-specific separator as a delimiter, then normalizes the
resulting path. */

path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
// Returns: '/foo/bar/baz/asdf'

path.join('foo', {}, 'bar');
// Throws 'TypeError: Path must be a string. Received {}'

Example 2: node.js name of file

var path = require('path');
var scriptName = path.basename(__filename);

Example 3: join method in express

app.use('/static', express.static(path.join(__dirname, 'public')))