Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LawEKS opened this issue Apr 5, 2018 · 0 comments
Open

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

LawEKS opened this issue Apr 5, 2018 · 0 comments

Comments

@LawEKS
Copy link

LawEKS commented Apr 5, 2018

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}`);
                }
            });
        })

    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant