import express from 'express';
import ip      from 'ip';

import leftpad from './left-pad';

const app  = express();
const port = process.env.PORT || 3000;

app.get('/', (req, res, next) => {
    let str = req.query.str;
    const ch  = req.query.ch;
    const len = req.query.len;

    typeof str === 'undefined' ? str = '' : str = str;
    res.status(200).json({ str: leftpad(str, len, ch) });
});

if (!module.parent) {
    app.listen(port, () => {
        console.log(`Express app running at ${ip.address()}:${port}`);
    });
}

export default app;

import express from 'express';
import ip      from 'ip';

import leftpad from './left-pad';

const app  = express();
const port = process.env.PORT || 3000;

app.get('/', (req, res) => {
    let   str = req.query.str;
    const ch  = req.query.ch;
    const len = req.query.len;

    if (typeof str === 'undefined') str = '';

    res.status(200).json({ str: leftpad(str, len, ch) });
});

if (!module.parent) {
    app.listen(port, () => {
        console.log(`Express app running at ${ip.address()}:${port}`);
    });
}

export default app;

Add even better check for undefined str parameter
Add even better check for undefined str parameter
