title: UDP javascript - Uncaught TypeError: dgram.createSocket is not a function
body: <p>I can´t fix this problem to create a UDP Socket in my project. i install dgram with npm. when i run : node app.js, works fine, but When a call this function in another class doesn´t work. Here is my code:</p>
  <pre><code>const dgram = require('dgram')
  import React from 'react';
  
  export default function read() {
  const server = dgram.createSocket('udp4')
  
  server.on('error',(error)=&gt;{
      console.log('error')
  server.close()
  })
  
  
  
  server.on('listening',()=&gt;{
      const address = server.address()
      console.log('on')
  })
  
  server.on('message',(message,senderInfo)=&gt;{
  
      console.log('recebido')
      server.send(message, senderInfo.port,senderInfo.address, ()=&gt;{
      console.log('test')})
      
  
  })
  
  server.bind(5500)
  }
  </code></pre>
  <p>this error apper:</p>
  <p>UDPread.js:11</p>
  <pre><code>   Uncaught TypeError: dgram.createSocket is not a function
  at read (UDPread.js:11:1)
  at onClick (PressResponder.js:364:1)
  at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
  at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
  at invokeGuardedCallback (react-dom.development.js:4056:1)
  at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070:1)
  at executeDispatch (react-dom.development.js:8243:1)
  at processDispatchQueueItemsInOrder (react-dom.development.js:8275:1)
  at processDispatchQueue (react-dom.development.js:8288:1)
  at dispatchEventsForPlugins (react-dom.development.js:8299:1)
  at react-dom.development.js:8508:1
  at batchedEventUpdates$1 (react-dom.development.js:22396:1)
  at batchedEventUpdates (react-dom.development.js:3745:1)
  at dispatchEventForPluginEventSystem (react-dom.development.js:8507:1)
  at attemptToDispatchEvent (react-dom.development.js:6005:1)
  at dispatchEvent (react-dom.development.js:5924:1)
  at unstable_runWithPriority (scheduler.development.js:468:1)
  at runWithPriority$1 (react-dom.development.js:11276:1)
  at discreteUpdates$1 (react-dom.development.js:22413:1)
  at discreteUpdates (react-dom.development.js:3756:1)
  at dispatchDiscreteEvent (react-dom.development.js:5889:1)
  </code></pre>
  <p>any solution?</p>