Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coap

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coap

A CoAP library for node modelled after 'http'

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.1K
decreased by-11.55%
Maintainers
1
Weekly downloads
 
Created
Source

node-coap

Build
Status

node-coap is an highly experimental client and (in the future) server library for CoAP modelled after the http module.

What is CoAP?

Constrained Application Protocol (CoAP) is a software protocol intended to be used in very simple electronics devices that allows them to communicate interactively over the Internet. - Wikipedia

This library follows the draft-18 of the standard.

It does not parse the protocol but it use CoAP-packet instead.

This has been tested only on node v0.10.

Installation

$: npm install coap --save

Basic Example

The following example opens a UDP server and sends a CoAP message to it:

const dgram       = require('dgram')
    , coapPacket  = require('coap-packet')
    , parse       = packet.parse
    , payload     = new Buffer('Hello World')
    , port        = 41234
    , server      = dgram.createSocket("udp4")
    , coap        = require('coap')

server.bind(port, function() {
  coap.request('coap://localhost:' + port).end(paylaod)
})

server.on('message', function(data) {
  console.log(parse(data).payload.toString())
  server.close()
})

API

request(url)

Execute a CoAP request. url can be a string or an object. If it is a string, it is parsed using require('url').parse(url). If it is an object:

  • host: A domain name or IP address of the server to issue the request to. Defaults to 'localhost'.
  • hostname: To support url.parse() hostname is preferred over host
  • port: Port of remote server. Defaults to 5483.
  • method: A string specifying the CoAP request method. Defaults to 'GET'.
  • pathname: Request path. Defaults to '/'. Should not include query string
  • query: Query string. Defaults to ''. Should not include the path, e.g. 'a=b&c=d'

coap.request() returns an instance of stream.Writable. If you need to add a payload, just pipe into it. Otherwise, you must call end to submit the request.

Contributors

Coap-Packet is only possible due to the excellent work of the following contributors:

Matteo CollinaGitHub/mcollinaTwitter/@matteocollina

LICENSE

Copyright (c) 2013 node-coap contributors (listed above).

Coap-Packet is licensed under an MIT +no-false-attribs license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

Keywords

FAQs

Package last updated on 05 Oct 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc