Answer the following questions considering the learning outcomes for this week. Make sure to record evidence of your processes. You can use code snippets, screenshots or any other material to support your answers.
Do not fill in the feedback section. The Founders and Coders team will update this with feedback on your progress.
- By creating a constant PORT and assigning it
process.env.PORT
, the port the server runs on can be set via an environmental variable when starting the server, e.g.PORT=7777 node index.js
. If no environmental variable is passed in, thenprocess.env.PORT
will beundefined
, which evaluates to falsey and PORT will be assigned the value of 3000 as well due to the OR operator||
.
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => console.log(`listening at http://localhost:${PORT}`));
- Writing back-end tests turned out to be a lot more complicated an affair than the simple synchronous function tests for javascript code running in the browser I'd done up to this point. It was a very productive experience though, and I'll keep practicing!
- Mark was super helpful, and very knowledgable whenever we ran into technical difficulties.
Beth
You’ve demonstrated a solid understanding of environment variables and server configuration ⚡️
Consider taking on the QA role in a future project. A good place to start is selecting a simple server route within the project and writing tests for it independently. You can also explore asynchronous testing. Practice handling asynchronous code, using tools like async/await or promises, to ensure your tests can handle real-world scenarios effectively 🦑