A
A
Alexey Dugnist2015-12-17 16:44:48
Node.js
Alexey Dugnist, 2015-12-17 16:44:48

Why is express not returning res.send?

There is a method:

writeFile = ( name, pdfData, filename, callback ) ->

  fs.writeFile filename, pdfData, { flags: 'wx' }, ( err ) ->

    if err

      callback ''
      console.log err

    else

      callback name
      console.log 'saved'

Below is the route:
app.post '/upload', (( req, res, next ) ->

  filename = path.join __dirname, '/../../public/media/' + req.body.name + '.pdf'

  pdfData = new Buffer req.body.file, 'base64'
     
  writeFile req.body.name, pdfData, filename, ( name ) ->

    if name isnt ''

      # console.log name
      res.send 'Hello prev'

      next()

), (req, res) ->

  res.send 'Hello next'

Neither before next() nor after - res.send does not work...
What is the reason...?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Dugnist, 2015-12-29
@Peekab0o

In fact, the answer came, I just received it incorrectly on the client ...

S
SagePtr, 2015-12-17
@SagePtr

And name in function gets non-empty? If empty, then the next middleware in the chain will not be called and the function will close without even closing the connection with the client.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question