{"id":20317269,"url":"https://github.com/suryakarmakar/nodejs-response","last_synced_at":"2025-03-04T09:16:01.635Z","repository":{"id":143241043,"uuid":"436317038","full_name":"SuryaKarmakar/NodeJS-Response","owner":"SuryaKarmakar","description":"⚡how to send a http response (html or json) to the frontend using vanilla node js","archived":false,"fork":false,"pushed_at":"2021-12-11T10:24:11.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-14T13:16:19.305Z","etag":null,"topics":["http-response","response","vanilla-nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SuryaKarmakar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-08T16:31:14.000Z","updated_at":"2021-12-11T10:27:56.000Z","dependencies_parsed_at":"2023-07-20T19:31:10.042Z","dependency_job_id":null,"html_url":"https://github.com/SuryaKarmakar/NodeJS-Response","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuryaKarmakar%2FNodeJS-Response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuryaKarmakar%2FNodeJS-Response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuryaKarmakar%2FNodeJS-Response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuryaKarmakar%2FNodeJS-Response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SuryaKarmakar","download_url":"https://codeload.github.com/SuryaKarmakar/NodeJS-Response/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241818890,"owners_count":20025210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-response","response","vanilla-nodejs"],"created_at":"2024-11-14T18:30:28.590Z","updated_at":"2025-03-04T09:16:01.617Z","avatar_url":"https://github.com/SuryaKarmakar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sending Response To The Frontend\n\n- **res.writeHead** to set any response headers.\n\n```js\nres.writeHead(200, { \"Content-Type\": \"text/html\" });\n```\n\n- **res.write()** to send the actual content for the response. the content should be either raw html or json data.\n\n```js\nres.write(\"\u003ch1\u003eWelcome to vanilla node server\u003c/h1\u003e\");\n```\n\nor,\n\n```js\nres.write(JSON.stringify(data));\n```\n\n- **res.end()** to end the response.\n\n```js\nres.end();\n```\n\n## Send html response :\n\n```js\nres.writeHead(200, { \"Content-Type\": \"text/html\" });\nres.write(\"\u003ch1\u003eWelcome to vanilla node server\u003c/h1\u003e\");\nres.end();\n```\n\n## Send json response :\n\n```js\nres.writeHead(200, { \"Content-Type\": \"application/json\" });\nres.write(JSON.stringify(data));\nres.end();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuryakarmakar%2Fnodejs-response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuryakarmakar%2Fnodejs-response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuryakarmakar%2Fnodejs-response/lists"}