{"_id":"@ematechlabs/cf-mongodb-polyfills","_rev":"2-d6679ce56d7cef4dbfb7468ced705a4d","name":"@ematechlabs/cf-mongodb-polyfills","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.2":{"name":"@ematechlabs/cf-mongodb-polyfills","version":"1.0.2","keywords":["cloudflare","worker","mongodb","polyfill"],"author":{"name":"James Choi","email":"choijjames@gmail.com"},"license":"Apache-2.0","_id":"@ematechlabs/cf-mongodb-polyfills@1.0.2","maintainers":[{"name":"jason.danley","email":"jason.danley@ematechlabs.com"}],"homepage":"https://github.com/jdanl89/cf-mongodb-polyfills#readme","bugs":{"url":"https://github.com/jdanl89/cf-mongodb-polyfills/issues"},"dist":{"shasum":"5abfb8ef98279a0dff676e303d42d082e59d8bc3","tarball":"https://registry.npmjs.org/@ematechlabs/cf-mongodb-polyfills/-/cf-mongodb-polyfills-1.0.2.tgz","fileCount":18,"integrity":"sha512-wIfpDUbhljRGsDl9M4JniCb76xcLt3N1Jz1H211r+KmYvT9wja+em2tnQRYifKDMlbS70hkH7cXiai84BCzkyg==","signatures":[{"sig":"MEUCIHO8YDR3RYmBNI6k6H0oDwaWtz0hd3Yecn0cf87QOYeeAiEA+nnJBLcyQszrC3f5tuO+hs6x0HYWEdF12MWBlwflCPA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":50965},"main":"./dist/index.ts","types":"./dist/index.d.ts","exports":{".":{"import":"./src/index.ts","require":"./src/index.ts"},"./dns":{"import":"./src/dns.ts","require":"./src/dns.ts"},"./net":{"import":"./src/net.ts","require":"./src/net.ts"},"./tls":{"import":"./src/tls.ts","require":"./src/tls.ts"},"./net-mock":{"import":"./src/net-mock.ts","require":"./src/net-mock.ts"}},"gitHead":"08eb7ce1bc86aa733e80b54a1da9c40efa16b3c4","scripts":{},"_npmUser":{"name":"jason.danley","email":"jason.danley@ematechlabs.com"},"repository":{"url":"git+https://github.com/jdanl89/cf-mongodb-polyfills.git","type":"git"},"_npmVersion":"10.9.2","description":"cloudflare worker polyfill for net, tls, and dns for making mongodb connections work in workerd","directories":{},"_nodeVersion":"22.14.0","dependencies":{"yn":"^3.1.1","arg":"^4.1.3","diff":"^4.0.2","acorn":"^8.14.1","acorn-walk":"^8.3.4","make-error":"^1.3.6","undici-types":"^6.21.0","create-require":"^1.1.1","v8-compile-cache-lib":"^3.0.1"},"_hasShrinkwrap":false,"devDependencies":{"ts-node":"^10.9.2","typescript":"^5.7.2","@types/node":"^22.10.2","@cloudflare/workers-types":"^4.20241205.0"},"_npmOperationalInternal":{"tmp":"tmp/cf-mongodb-polyfills_1.0.2_1746826159585_0.473255991514395","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@ematechlabs/cf-mongodb-polyfills","description":"cloudflare worker polyfill for net, tls, and dns for making mongodb connections work in workerd","repository":{"type":"git","url":"git+https://github.com/jdanl89/cf-mongodb-polyfills.git"},"version":"1.0.3","main":"./dist/index.js","exports":{".":{"import":"./dist/index.js","require":"./dist/index.js"},"./net":{"import":"./dist/net.js","require":"./dist/net.js"},"./tls":{"import":"./dist/tls.js","require":"./dist/tls.js"},"./dns":{"import":"./dist/dns.js","require":"./dist/dns.js"},"./net-mock":{"import":"./dist/net-mock.js","require":"./dist/net-mock.js"}},"scripts":{},"keywords":["cloudflare","worker","mongodb","polyfill"],"author":{"name":"James Choi","email":"choijjames@gmail.com"},"license":"Apache-2.0","devDependencies":{"@cloudflare/workers-types":"^4.20241205.0","@types/node":"^22.10.2","ts-node":"^10.9.2","typescript":"^5.7.2"},"dependencies":{"acorn":"^8.14.1","acorn-walk":"^8.3.4","arg":"^4.1.3","create-require":"^1.1.1","diff":"^4.0.2","make-error":"^1.3.6","undici-types":"^6.21.0","v8-compile-cache-lib":"^3.0.1","yn":"^3.1.1"},"types":"./dist/index.d.ts","bugs":{"url":"https://github.com/jdanl89/cf-mongodb-polyfills/issues"},"homepage":"https://github.com/jdanl89/cf-mongodb-polyfills#readme","_id":"@ematechlabs/cf-mongodb-polyfills@1.0.3","gitHead":"08eb7ce1bc86aa733e80b54a1da9c40efa16b3c4","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-0FCVmkYjNBVWJOlDM6pVIY+FpVgZo8zBPc507ajhHRFClLObf7x970HgdSAhyeASfjJIhhSaUGa2FmnzgTDNfA==","shasum":"bd062d28772763a8b21bbe4c6463464226a6e098","tarball":"https://registry.npmjs.org/@ematechlabs/cf-mongodb-polyfills/-/cf-mongodb-polyfills-1.0.3.tgz","fileCount":13,"unpackedSize":36245,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDJ++rB+nCwzaUbEqjP6dOCVwkQMa/eGM1n3UucVu70RwIgGLgtz1cjG0GfFZrIEsLeUQzEv4EOsJhZJTp6rEDqSrk="}]},"_npmUser":{"name":"jason.danley","email":"jason.danley@ematechlabs.com"},"directories":{},"maintainers":[{"name":"jason.danley","email":"jason.danley@ematechlabs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cf-mongodb-polyfills_1.0.3_1747108121320_0.10855167564031198"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-09T21:29:19.467Z","modified":"2025-05-13T03:48:41.700Z","1.0.2":"2025-05-09T21:29:19.835Z","1.0.3":"2025-05-13T03:48:41.503Z"},"bugs":{"url":"https://github.com/jdanl89/cf-mongodb-polyfills/issues"},"author":{"name":"James Choi","email":"choijjames@gmail.com"},"license":"Apache-2.0","homepage":"https://github.com/jdanl89/cf-mongodb-polyfills#readme","keywords":["cloudflare","worker","mongodb","polyfill"],"repository":{"type":"git","url":"git+https://github.com/jdanl89/cf-mongodb-polyfills.git"},"description":"cloudflare worker polyfill for net, tls, and dns for making mongodb connections work in workerd","maintainers":[{"name":"jason.danley","email":"jason.danley@ematechlabs.com"}],"readme":"# cf-mongodb-polyfills\r\nThis package allows the use of the `mongodb` npm package in a cloudflare worker. It does this by polyfilling the `net` and `tls` modules in the `mongodb` package to use the `cf-mongodb-polyfills` package instead.\r\n\r\nThis package was forked from [jchoi2x/cf-mongodb-polyfills](https://github.com/jchoi2x/cf-mongodb-polyfills) and transpiled from TS to JS.\r\n\r\n## Description\r\n\r\nCurrently cloudflare's workerd does not support using `mongodb` package to connect to mongodb. This is due to the fact that `net.createConnection` and `tls.connect` arent\r\nimplemented in the worker runtime ([ref](https://developers.cloudflare.com/workers/runtime-apis/nodejs/#nodejs-api-polyfills)) even with the `nodejs_compat` or `nodejs_compat_v2` compatiblity flags enabled.\r\n\r\nHowever, via the use of the [`module aliasing`](https://developers.cloudflare.com/workers/wrangler/configuration/#module-aliasing) feature in `wrangler.toml`, we can replace the `net` and `tls` modules in the `mongodb` package with polyfills in this package. This package provides polyfills for the `net` and `tls` modules which will use `cloudflare:sockets` npm package to create a tcp connection to the mongodb server.\r\n\r\n\r\n## Installation\r\n\r\nTo install the package, run:\r\n\r\n```sh\r\nnpm install cf-mongodb-polyfills\r\n```\r\n\r\n### Modify `wrangler.toml`\r\n\r\nTo use the package in a cloudflare worker app, you must create [module aliases](https://developers.cloudflare.com/workers/wrangler/configuration/#module-aliasing) in the wrangler.toml to point to the polyfills that are in this package.\r\n\r\n```toml\r\n# wrangler.toml\r\n# ...\r\n\r\n[alias]\r\n\"net\" = \"@jdanl89/cf-mongodb-polyfills/net\"\r\n\"dns\" = \"@jdanl89/cf-mongodb-polyfills/dns\"\r\n\"tls\" = \"@jdanl89/cf-mongodb-polyfills/tls\"\r\n```\r\n\r\n\r\n## Usage\r\n\r\nWith these changes in place, you can now use the `mongodb` package in your cloudflare worker app.\r\n\r\n```typescript\r\nimport { MongoClient } from 'mongodb';\r\n\r\nexport default {\r\n  async fetch(request, env, ctx): Promise<Response> {\r\n\r\n    // connect to atlas mongodb\r\n    const tlsClient = new MongoClient('mongodb+srv://sharedddas:sdfaqwevccfjkjde9ei@dvi.kevpg.mongodb.net/?retryWrites=true&w=majority&appName=dev');\r\n    await tlsClient.connect();\r\n\r\n    // connect to mongo running locally\r\n    const client = new MongoClient('mongodb://localhost:27017');\r\n    await client.connect();\r\n\r\n    const db = tlsClient.db('test');\r\n    const users = await db.collection('users').find({}).toArray().limit(10);\r\n\r\n    return Response.json({\r\n      users\r\n    })\r\n  },\r\n} satisfies ExportedHandler<Env>;\r\n```\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please open an issue or submit a pull request.\r\n","readmeFilename":"README.md"}