@vagnerereno/exemplo-http 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/index.js +26 -0
  3. package/package.json +11 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ Olá!!
package/index.js ADDED
@@ -0,0 +1,26 @@
1
+ const http = require('http'); // Importa o módulo HTTP nativo
2
+
3
+ const server = http.createServer((req, res) => {
4
+
5
+ if (req.url === '/user') {
6
+ // Define o tipo de resposta como JSON
7
+ res.writeHead(200, { 'Content-Type': 'application/json' });
8
+ // Envia o JSON do "usuário"
9
+
10
+ const usuario = {
11
+ id: 1,
12
+ nome: "Maria",
13
+ email: "maria@teste.com"
14
+ };
15
+ res.end(JSON.stringify(usuario));
16
+ } else {
17
+ // Rota não encontrada
18
+ res.writeHead(404);
19
+ res.end("Rota não encontrada.");
20
+ }
21
+ });
22
+
23
+ // Servidor escutando na porta 3000
24
+ server.listen(3000, () => {
25
+ console.log("Servidor em execução em http://localhost:3000");
26
+ });
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@vagnerereno/exemplo-http",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "author": "",
9
+ "license": "ISC",
10
+ "description": ""
11
+ }