View Code? Open in Web Editor
NEW
This project forked from truecodersio/node_streams
JavaScript 64.46%
HTML 35.54%
node_streams's Introduction
- In VS Code, create and open a new folder named “node_streams”
- Create a streams.js file
- Import or require the fs module
- Create a server
- Write a conditional statement that checks the request url for a “GET” request on a “/”
- If the method and url match the previous check (step c), use createReadStream to pipe the contents of an html file to the client
- You can design the html file however you choose
- If the method and url are not “/” and “GET”, use the same method to pipe the contents of a 404 not found html page
- You should send the appropriate status code and headers
- Now run node app and test in postman or the browser
- In a new file, fetch data from a source of your choosing (e.g. Pokemon)
- Use the createWriteStream method to create a write stream using an empty json file in your project
- Use the write method to populate the json file with the data from your fetch request
- You will need to use a third-party fetch api (isomorphic-fetch, node-fetch, Axios, etc) to achieve this in Node