Hello World, Good Morning!
Im stucked in Basic Node and Express - Use the .env File. Im using Repl.it and it does not have an .env file. So i created one and this is what i put in it
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
Not quite. It is shorthand for telling your app this:
app.route('/json').get((req, res) => {// Do something}
Tells your app to do something, when a GET request is made to the endpoint /json
That “something” could be “add the numbers 1 and 2”, or “respond with a json object”.
Now, the response is the thing passed to the second argument of the callback function. Information about the request is the first argument.
So, going back to the lesson:
Let’s create a simple API by creating a route that responds with JSON at the path /json . You can do it as usual, with the app.get() method. Inside the route handler, use the method res.json() , passing in an object as an argument. This method closes the request-response loop, returning the data.
I did try to do wrapping the if statement in res.json (i did also try to wrap all the if in a single res.json) but it didn’t work as well…
I still doing it wrong? (sorry im a rookie)
Remember, (req, res) => { } is just like any other function.
So, if I asked you to write me a function which accepted a request and response as arguments, but responded with a different message depending on the value of MESSAGE_STYLE, how would you go about writing that?