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

erro na deleção


C:\Program Files\nodejs\alurapic>npm start

> alurapic@1.0.0 start C:\Program Files\nodejs\alurapic
> node server.js

consign v0.1.2 Initialized in app
+ .\api\foto.js
+ .\api\grupo.js
+ .\routes\foto.js
+ .\routes\grupo.js
C:\Program Files\nodejs\alurapic\node_modules\express\lib\router\route.js:196
        throw new Error(msg);
        ^

Error: Route.delete() requires callback functions but got a [object Undefined]
    at Route.(anonymous function) [as delete] (C:\Program Files\nodejs\alurapic\
node_modules\express\lib\router\route.js:196:15)
    at EventEmitter.app.(anonymous function) [as delete] (C:\Program Files\nodej
s\alurapic\node_modules\express\lib\application.js:481:19)
    at Function.module.exports (C:\Program Files\nodejs\alurapic\app\routes\foto
.js:10:12)
    at Consign.into (C:\Program Files\nodejs\alurapic\node_modules\consign\lib\c
onsign.js:239:17)
    at Object.<anonymous> (C:\Program Files\nodejs\alurapic\config\express.js:16
:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.10.1
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! alurapic@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the alurapic@1.0.0 start script 'node server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the alurapic package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs alurapic
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls alurapic
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Program Files\nodejs\alurapic\npm-debug.log

C:\Program Files\nodejs\alurapic>
app.delete('/v1/fotos/:id', api.RemovePorId); 


api.removePorId = function(req, res){

    fotos = fotos.filter(function(foto){
        return foto._id != req.params.id;
    });    
    res.sendStatus(204);

};

no meu ver parece que o

res.sendStatus(204); nao esta funcionando direito testei o res.status(204).end(); mas tb nao funcionou

5 respostas

Tenta assim:

api.removePorId = function(req, res){

    fotos = fotos.filter(function(foto){
        return foto._id != req.params.id;
    });    
    res.sendStatus(204);

};


app.delete('/v1/fotos/:id', api.RemovePorId);

não funcionou nao, colei os dois pedaços de codigo na api/foto.js e na routes/foto.js mas o erro ta igual. Obs:como e ruim nao ter um debug

ah, e os dois removePorId com letra minuscula.

solução!

Como Alberto apontou é um erro de digitação.

agora funcionou , obrigado !