How to receive a JSON file from a glitch-hello-website to a node.js app

Hi I’m trying to make a login thing in html and I’m trying to make it so basically you type your email in the box and then it emails you a code that you have to type to login, basically like glitch’s “magic email” login. I got the email system set up and here is what I’m trying to do. In my website the script does a http POST and the node.js app receives a JSON file so it can email someone. Then the node.js app can returns the code. I just need help on sending the JSON file and returning a 6 digit code. Please help!

Do you have some code we can work on, for the JSON sending part?

Here is the Website code and Node.Js code

Uhhh, what about the POST request part?

I haven’t added that yet and that’s the part I need help on

1 Like

Sorry for asking so many questions, but do you have the code that does this?

No I don’t have the code for that yet.

Now’s a good a time to start on that as any! Here’s a guide on how to POST a JSON file Using Fetch - Web APIs | MDN

You end up needing to do it from JavaScript, because forms tend to encode stuff in other formats, such as urlencoded.

I did that on my website but how do I set it to receive on my node.js app?

what framework are you using on the server side? express?

Yeah on node.js

Express 4.x - API Reference they have a middleware for accepting JSON data. use that, and you can get the stuff with req.body Express 4.x - API Reference

Thanks but is it possible to send the JSON file from a glitch-hello-website to a node.js app?

yup, you can use nodejs’s http or https module. or if you already have code what works with fetch in a browser, you can get the node-fetch package from npm to run it on the server


I’ve been trying to understand how to do it on that website you linked but I still don’t know.

uh-oh, I hadn’t linked to the websites about the latest understanding of what you’re trying to do! but here’s a link for that right now: node-fetch - npm

maybe see if you can get that snippet working in isolation and then integrate it into your node.js project.

also, to clarify: this is less “send from the static site” and more “request from the node.js app”

1 Like

I looked on the site and I could figure out how to do it. I’m new to JavaScript btw

cool, glad to hear that the example worked out. were you later able to use one of these techniques in your project?

Oops there was a typo I meant I couldn’t do it

oh shoot :grimacing: maybe you could share how far you got and your thoughts on what’s going wrong with the latest attempt?