![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
simple-cookie-client
Advanced tools
Simple and isomorphic cookie api, with support for hybrid client-side and server-side rendering applications.
Simple and isomorphic cookie api, with support for hybrid client-side and server-side rendering applications.
npm install simple-cookie-client
import { getCookie } from 'simple-cookie-client';
const cookie = getCookie({ name: 'authorization' }); // returns `null` or `Cookie`
Supports both browser and server side env.
import { setCookie } from 'simple-cookie-client';
setCookie({ name: 'authorization', '821' });
Supports both browser and server side env.
import { deleteCookie } from 'simple-cookie-client';
deleteCookie({ name: 'authorization' });
Supports both browser and server side env.
import { getCookiesFromString } from 'simple-cookie-client';
const cookies = getCookiesFromString('authorization=abc; _ga=123') // => [Cookie({ name: 'authorization', value: 'abc'}), Cookie({ name: '_ga', value: '123' })]
In serverside rendering, you may need a cookie that is accessible to your clientside application in the document
but not in your serverside application context. Typically, the same cookie that is accessible in the browser in the document
object - is accessible on the server in the request
object sent to your server.
Therefore, this library supports exposing cookies from the request in a way that is isomorphic (i.e., looks the same) to the clientside code you're writing.
For example, in a Next.JS application, you are able to access the req
object with getServerSideProps
. Here is how you can expose the cookie in that environment:
import { exposeCookieFromReq } from 'simple-cookie-client';
export const getStaticProps = async ({ req }) =>
exposeCookieFromReq({
name, // the name of the cookie you want to expose
req, // the request object next.js was given
});
And now, any code in your stack can access that cookie without needing to think about whether it gets it from the browser directly or whether it was exposed like above:
const cookie = getCookie({ name }); // this will work both in SSR (if cookie was exposed from req) as well as browser (where cookie is in `document` api)
FAQs
Simple and isomorphic cookie api, with support for hybrid client-side and server-side rendering applications.
The npm package simple-cookie-client receives a total of 0 weekly downloads. As such, simple-cookie-client popularity was classified as not popular.
We found that simple-cookie-client demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.