Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
wrangler
Advanced tools
The wrangler npm package is a command-line tool for building, deploying, and managing Cloudflare Workers projects. It simplifies the process of working with Cloudflare's serverless platform, allowing developers to focus on writing code rather than managing infrastructure.
Creating a new Cloudflare Workers project
This command initializes a new Cloudflare Workers project in a directory named 'my-worker'. It sets up the necessary configuration files and project structure.
npx wrangler generate my-worker
Publishing a Cloudflare Worker
This command deploys your Cloudflare Worker to the Cloudflare network. It reads the configuration from the wrangler.toml file and uploads your code to Cloudflare.
npx wrangler publish
Previewing a Cloudflare Worker
This command allows you to preview your Cloudflare Worker in a browser before deploying it. It provides a temporary URL where you can test your worker.
npx wrangler preview
Managing environment variables
This command allows you to securely store environment variables for your Cloudflare Worker. You will be prompted to enter the value for the secret, which will then be encrypted and stored.
npx wrangler secret put MY_SECRET
The Serverless Framework is a popular open-source framework for building and deploying serverless applications across various cloud providers, including AWS, Azure, and Google Cloud. It offers a broader range of integrations and features compared to wrangler, which is specific to Cloudflare Workers.
Architect (or @architect) is an open-source framework for building and deploying serverless applications on AWS. It provides a simple and declarative way to define serverless infrastructure and focuses on developer productivity. Unlike wrangler, which is Cloudflare-specific, Architect is designed for AWS.
Claudia.js is a tool for deploying Node.js projects to AWS Lambda and API Gateway. It automates many of the deployment steps and simplifies the process of creating and managing serverless applications on AWS. Claudia.js is more AWS-centric, whereas wrangler is tailored for Cloudflare Workers.
A comprehensive, compact MIME type module.
Version 2 is a breaking change from 1.x as the semver implies. Specifically:
lookup()
renamed to getType()
extension()
renamed to getExtension()
charset()
and load()
methods have been removedIf you prefer the legacy version of this module please npm install mime@^1
. Version 1 docs may be found here.
npm install mime
It is recommended that you use a bundler such as webpack or browserify to package your code. However, browser-ready versions are available via wzrd.in. E.g. For the full version:
<script src="https://wzrd.in/standalone/mime@latest"></script>
<script>
mime.getType(...); // etc.
</script>
Or, for the mime/lite
version:
<script src="https://wzrd.in/standalone/mime%2flite@latest"></script>
<script>
mimelite.getType(...); // (Note `mimelite` here)
</script>
For the full version (800+ MIME types, 1,000+ extensions):
const mime = require('mime');
mime.getType('txt'); // ⇨ 'text/plain'
mime.getExtension('text/plain'); // ⇨ 'txt'
See Mime API below for API details.
There is also a "lite" version of this module that omits vendor-specific
(*/vnd.*
) and experimental (*/x-*
) types. It weighs in at ~2.5KB, compared
to 8KB for the full version. To load the lite version:
const mime = require('mime/lite');
For those of you wondering about the difference between these [popular] NPM modules, here's a brief rundown ...
mime-db
is "the source of
truth" for MIME type information. It is not an API. Rather, it is a canonical
dataset of mime type definitions pulled from IANA, Apache, NGINX, and custom mappings
submitted by the Node.js community.
mime-types
is a thin
wrapper around mime-db that provides an API drop-in compatible(ish) with mime @ < v1.3.6
API.
mime
is, as of v2, a self-contained module bundled with a pre-optimized version
of the mime-db
dataset. It provides a simplified API with the following characteristics:
Module | Size |
---|---|
mime-db | 18 KB |
mime-types | same as mime-db |
mime | 8 KB |
mime/lite | 2 KB |
Both require('mime')
and require('mime/lite')
return instances of the MIME
class, documented below.
Note: Inputs to this API are case-insensitive. Outputs (returned values) will be lowercase.
Most users of this module will not need to create Mime instances directly. However if you would like to create custom mappings, you may do so as follows ...
// Require Mime class
const Mime = require('mime/Mime');
// Define mime type -> extensions map
const typeMap = {
'text/abc': ['abc', 'alpha', 'bet'],
'text/def': ['leppard']
};
// Create and use Mime instance
const myMime = new Mime(typeMap);
myMime.getType('abc'); // ⇨ 'text/abc'
myMime.getExtension('text/def'); // ⇨ 'leppard'
If more than one map argument is provided, each map is define()
ed (see below), in order.
Get mime type for the given path or extension. E.g.
mime.getType('js'); // ⇨ 'application/javascript'
mime.getType('json'); // ⇨ 'application/json'
mime.getType('txt'); // ⇨ 'text/plain'
mime.getType('dir/text.txt'); // ⇨ 'text/plain'
mime.getType('dir\\text.txt'); // ⇨ 'text/plain'
mime.getType('.text.txt'); // ⇨ 'text/plain'
mime.getType('.txt'); // ⇨ 'text/plain'
null
is returned in cases where an extension is not detected or recognized
mime.getType('foo/txt'); // ⇨ null
mime.getType('bogus_type'); // ⇨ null
Get extension for the given mime type. Charset options (often included in Content-Type headers) are ignored.
mime.getExtension('text/plain'); // ⇨ 'txt'
mime.getExtension('application/json'); // ⇨ 'json'
mime.getExtension('text/html; charset=utf8'); // ⇨ 'html'
Define [more] type mappings.
typeMap
is a map of type -> extensions, as documented in new Mime
, above.
By default this method will throw an error if you try to map a type to an
extension that is already assigned to another type. Passing true
for the
force
argument will suppress this behavior (overriding any previous mapping).
mime.define({'text/x-abc': ['abc', 'abcd']});
mime.getType('abcd'); // ⇨ 'text/x-abc'
mime.getExtension('text/x-abc') // ⇨ 'abc'
mime [path_or_extension]
E.g.
> mime scripts/jquery.js
application/javascript
Markdown generated from src/README_js.md by
FAQs
Command-line interface for all things Cloudflare Workers
The npm package wrangler receives a total of 552,433 weekly downloads. As such, wrangler popularity was classified as popular.
We found that wrangler demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.