Solucionado (ver solução)
Solucionado
(ver solução)
5
respostas

Erro ao iniciar servidor de LOG

Segue o log do erro:

0 verbose cli [
0 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
0 verbose cli   'C:\\Users\\andre\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli   'start'
0 verbose cli ]
1 info using npm@7.21.0
2 info using node@v14.17.5
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:C:\Users\andre\AppData\Roaming\npm\node_modules\npm\npmrc Completed in 2ms
6 timing config:load:builtin Completed in 2ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:C:\Users\andre\Desktop\angular-p1\log-server\.npmrc Completed in 0ms
10 timing config:load:project Completed in 2ms
11 timing config:load:file:C:\Users\andre\.npmrc Completed in 1ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:C:\Users\andre\AppData\Roaming\npm\etc\npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:credentials Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 10ms
19 timing npm:load:configload Completed in 11ms
20 timing npm:load:setTitle Completed in 0ms
21 timing npm:load:setupLog Completed in 1ms
22 timing config:load:flatten Completed in 2ms
23 timing npm:load:cleanupLog Completed in 1ms
24 timing npm:load:configScope Completed in 0ms
25 timing npm:load:projectScope Completed in 1ms
26 timing npm:load Completed in 16ms
27 timing command:run-script Completed in 15ms
28 timing command:start Completed in 19ms
29 verbose stack Error: Missing script: "start"
29 verbose stack
29 verbose stack Did you mean one of these?
29 verbose stack     npm star # Mark your favorite packages
29 verbose stack     npm stars # View packages marked as favorites
29 verbose stack
29 verbose stack To see a list of scripts, run:
29 verbose stack   npm run
29 verbose stack     at RunScript.run (C:\Users\andre\AppData\Roaming\npm\node_modules\npm\lib\run-script.js:104:13)
30 verbose cwd C:\Users\andre\Desktop\angular-p1\log-server
31 verbose Windows_NT 10.0.19043
32 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\andre\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
33 verbose node v14.17.5
34 verbose npm  v7.21.0
35 error Missing script: "start"
35 error
35 error Did you mean one of these?
35 error     npm star # Mark your favorite packages
35 error     npm stars # View packages marked as favorites
35 error
35 error To see a list of scripts, run:
35 error   npm run
36 verbose exit 1
5 respostas

Olá, André! Tudo certo?

Realmente é um problema na própria API, que está sem o script start.

Pare resolver, vá no arquivo package.json do log-server e dentro de scripts adicione o seguinte:

"start": "node server.js",

O resultado do scripts será:

  "scripts": {
    "start": "node server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

Depois disso, pode rodar npm start normalmente!

Espero que ajude, bons estudos!

Apresentou o seguinte erro:

> log-server@1.0.0 start
> node server.js

internal/modules/cjs/loader.js:892
  throw err;
  ^

Error: Cannot find module 'C:\Users\andre\Desktop\angular-p1\log-server\server.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

O erro está dizendo que não encontrou o módulo server.js na raiz de log-server, você vê esse arquivo por aí?

Se você não encontrou, sugiro baixar novamente essa API no projeto e abrir a pasta comprimida, antes de extrair o conteúdo, confirme que o server.js está ali.

O log-server.zip disponibilizado na transcrição da aula contém apenas o node_modules e o package.json

solução!

Estranho, baixei aqui e os outros arquivos vieram. Não sei se algo como um antivírus poderia remover o server.js.

De toda forma, o código é pequeno, então vou te passar por aqui mesmo, certo?

Na raiz da pasta log-server, crie um arquivo server.js e nele cole o seguinte código:

const express = require('express'),
    bodyParser = require('body-parser'),
    cors = require('cors'),
    app = express();

const corsOptions = {
    exposedHeaders: ['x-access-token']
};

app.use(cors(corsOptions));

app.use(bodyParser.json());

app.post('/infra/log', (req, res) => {
    console.log(req.body);
    res.end();
});

app.listen(7000, () => {
    console.log('Log server is running!');
});

No package.json, confirme que o conteúdo é o seguinte:

{
  "name": "log-server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node server.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.3",
    "cors": "^2.8.4",
    "express": "^4.16.3"
  }
}

A API deve funcionar agora, mas qualquer coisa avise!