Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Routr library is an implementation of router-related functionalities that can be used for both server and client. It follows the same routing rules as Express by using the same library. This library does not use callbacks for routes, instead just mapping them to string names that can be used as application state and used within your application later. For instance in Flux, the current route would be held as state in a store.
For more detailed examples, please check out example applications;
import Router from 'routr';
const router = new Router([
{
name: 'view_user',
path: '/user/:id',
method: 'get',
foo: {
bar: 'baz',
},
},
{
name: 'view_user_post',
path: '/user/:id/post/:post',
method: 'get',
},
]);
// match route
const route = router.getRoute('/user/garfield?foo=bar');
if (route) {
// this will output:
// - "view_user" for route.name
// - "/user/garfield" for route.url
// - {id: "garfield"} for route.params
// - {path: "/user/:id", method: "get", foo: { bar: "baz"}} for route.config
// - { foo: 'bar' } for route.query
console.log('[Route found]:', route);
}
// generate path name (does not include query string) from route
// "path" will be "/user/garfield/post/favoriteFood?meal=breakfast"
const path = router.makePath(
'view_user_post',
{ id: 'garfield', post: 'favoriteFood' },
{ meal: 'breakfast' }
);
We use Object.freeze
to freeze the router and route objects for non-production environments to ensure the immutability of these objects.
For production environments, it is recommended to use tools like envify along with uglify as part of your build process to strip out the production specific code for performance benefits.
We use if (process.env.NODE_ENV !== 'production')
to wrap around Object.freeze()
, so that you can use various tools to build the code for different environments:
Two main utility plugins:
process.env
Example of the webpack configuration:
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin(),
...
]
Similar to webpack, you can also use the following two utils with your favorite build system:
Command-line example:
$ browserify index.js -t [ envify --NODE_ENV production ] | uglifyjs -c > bundle.js
This software is free to use under the Yahoo! Inc. BSD license. See the LICENSE file for license text and copyright information.
Third-pary open source code used are listed in our package.json file.
3.0.0
routr
uses native URLSearchParams
instead of query-string
to parse query strings. As a consequence, parsing ?foo
will result in { foo: '' }
as specified in the WHATWG spec instead of { foo: null }
as query-string
would do. Also, URLSearchParams
is not available in older browsers (noticeably IE11). If you need to support them, you can either add a URLSearchParams
polyfill or inject query-string
when instantiating routr
:router = new Routr(routes, {
queryLib: require('query-string'),
});
path-to-regexp
to its latest versionFAQs
A router for both server and client
The npm package routr receives a total of 370 weekly downloads. As such, routr popularity was classified as not popular.
We found that routr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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 found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.