Skip to content

Week 6, Day 2, PG-workshop - 'create-user' endpoint  #31

@LawEKS

Description

@LawEKS
else if (endpoint === 'create-user')  {
        // Read html form request data using a Stream

        let body = '';
        request.on('data', (chunk) => body += chunk);
        request.on('end', () => {  
            const { name, location } = querystring.parse(body);
            addData(name, location, (err, res) => {
                if (err) {
                    response.writeHead(303, {'Location': '/'});
                    response.writeHead(500, {'content-type': 'text/plain'});
                    response.end('Something went wrong');
                } else {
                    response.writeHead(200, {'content-type': 'text/plain'});
                    response.writeHead(303, {'Location': '/'});
                    response.end(`Successfully added ${name}`);
                }
            });
        })

    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions