E
E
embiid2021-12-20 15:41:46
Node.js
embiid, 2021-12-20 15:41:46

How to send a request to such a method?

Found backing for the front. Not strong in node.js. Can you explain how I can create an object? I use postman, I send in body json:

{
    "name": "asd"
}


And I get the answer: "Cannot POST /"

.post('/', function (req, res) {
    var directory = _.pick(req.body, [
          'parentId',
          'name'
        ]
      )
      , parent = _.find(store.directories, function (dir) {
        return dir.id == directory.parentId
      })

    if (parent) {
      _.assign(directory, { id: idGenerator.getNext() })
      store.directories.push(directory)

      res.send(directory)
    } else {
      res.status(500).send('no parent')
    }
  })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ikutin666, 2021-12-21
@ikutin666

.post('/'...
says that this is a handler for the root path
if the server is running on localhost:3000
then you need to send post to localhost:3000

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question