I am trying to create a function ......
curl -v -X POST http://localhost:8091/functions/v1/libraries/math/function/dateEpoc -H 'content-type: application/json' -d '{"name": "dateEpoc", "code": "function dateEpoc(epoc) { let date = new Date(); return date.setUTCSeconds(epoc); }"}' -u Administrator:password
but I am getting an error
Connected to localhost (::1) port 8091 (#0) Server auth using Basic with user 'Administrator' POST /functions/v1/libraries/math/function/dateEpoc HTTP/1.1 Host: localhost:8091 Authorization: Basic QWRtaW5pc3RyYXRvcjp0aGlyZGV5ZUAzMQ== User-Agent: curl/7.55.1 Accept: / Content-Length: 7 Content-Type: application/x-www-form-urlencoded
upload completely sent off: 7 out of 7 bytes HTTP/1.1 404 Object Not Found Cache-Control: no-cache,no-store,must-revalidate Connection: close Content-Length: 31 Content-Type: text/plain Date: Mon, 23 Nov 2020 10:19:52 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT Pragma: no-cache Server: Couchbase Server X-Content-Type-Options: nosniff X-Frame-Options: DENY X-Permitted-Cross-Domain-Policies: none X-XSS-Protection: 1; mode=block
The 404 is down to the fact that you are using the wrong service to create the javascript function body. Change the port from 8091 to 8093 - this will direct the request to the N1QL service rather than ns_server, and the request should be processed properly.