Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cmmv/cookie-parser

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cmmv/cookie-parser

CMMV (@cookie-parser)

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
328
increased by137.68%
Maintainers
1
Weekly downloads
 
Created
Source

CMMV Logo

Contract-Model-Model-View (CMMV)
A minimalistic framework for building scalable and modular applications using TypeScript contracts.

NPM Version Package License CircleCI

DocumentationReport Issue

Description

@cmmv/server is inspired by the popular Express.js framework but has been entirely rewritten in TypeScript with performance improvements in mind. The project integrates common plugins like body-parser, compression, cookie-parser, cors, etag, helmet and serve-static out of the box. Additionally, it plans to support any Express.js-compatible plugin in the near future.

Installation

Install the @cmmv/server package via npm:

$ npm install @cmmv/server @cmmv/server-static

Quick Start

Below is a simple example of how to create a new CMMV application:

//import { readFileSync } from "node:fs";

import cmmv, { json, urlencoded, serverStatic } from '@cmmv/server';
import etag from '@cmmv/etag';
import cors from '@cmmv/cors';
import cookieParser from '@cmmv/cookie-parser';
import compression from '@cmmv/compression';
import helmet from '@cmmv/helmet';

const app = cmmv({
    /*http2: true,
    https: {
        key: readFileSync("./cert/private-key.pem"),
        cert: readFileSync("./cert/certificate.pem"),
        passphrase: "1234"
    }*/
});

const host = '0.0.0.0';
const port = 3000;

app.use(serverStatic('public'));
app.use(cors());
app.use(etag({ algorithm: 'fnv1a' }));
app.use(cookieParser());
app.use(json({ limit: '50mb' }));
app.use(urlencoded({ limit: '50mb', extended: true }));
app.use(compression({ level: 6 }));
app.use(
    helmet({
        contentSecurityPolicy: {
            useDefaults: false,
            directives: {
                defaultSrc: ["'self'"],
                scriptSrc: ["'self'", 'example.com'],
                objectSrc: ["'none'"],
                upgradeInsecureRequests: [],
            },
        },
    }),
);

app.set('view engine', 'pug');

app.get('/view', function (req, res) {
    res.render('index', { title: 'Hey', message: 'Hello there!' });
});

app.get('/', async (req, res) => {
    res.send('Hello World');
});

app.get('/json', async (req, res) => {
    res.json({ hello: 'world' });
});

app.get('/user/:id', async (req, res) => {
    res.send('User ' + req.params.id);
});

app.get('/users', async (req, res) => {
    res.json(req.query);
});

app.post('/test', async (req, res) => {
    console.log(req.body);
    res.send('ok');
});

app.listen({ host, port })
.then(server => {
    //console.log(app.server)
    console.log(
        `Listen on http://${server.address().address}:${server.address().port}`,
    );
})
.catch(err => {
    throw Error(err.message);
});

Features

  • Performance Optimized: Faster and more efficient with improvements over Express.js.
  • Built-in Plugins: Includes commonly used middleware like compression, body-parser, cookie-parser, and more.
  • TypeScript First: Fully written in TypeScript for better type safety and developer experience.
  • Express.js Compatibility: Plans to support Express.js-compatible plugins.
  • HTTP/2 Support: Native support for HTTP/2, improving speed and connection performance.

Benchmarks

  • https://github.com/fastify/benchmarks
  • Machine: linux x64 | 32 vCPUs | 256.6GB Mem
  • Node: v20.17.0
  • Run: Thu Oct 02 2024 15:23:41 GMT+0000 (Coordinated Universal Time)
  • Method: autocannon -c 100 -d 40 -p 10 localhost:3000
FrameworkVersionRouterRequests/sLatency (ms)Throughput/Mb
polka0.5.247499.220.618.47
connect3.7.047233.620.708.42
barev20.17.046587.220.998.31
fastify5.0.046321.021.178.30
server-base-router7.1.3246158.621.198.23
micro10.0.145477.421.558.11
rayo1.4.645397.621.598.10
server-base7.1.3244877.021.858.00
micro-route2.5.043836.622.377.82
connect-router1.3.843080.022.787.68
cmmv0.0.1141603.923.607.46
restana4.9.941601.823.577.42
hono4.6.341482.123.667.40
polkadot1.0.040766.624.087.27
0http3.5.338630.625.446.89
koa2.15.338582.825.466.88
take-five2.0.037030.626.5913.31
h31.13.036602.226.866.53
koa-isomorphic-router1.0.136570.626.886.52
h3-router1.13.035513.827.706.33
koa-router12.0.135363.827.846.31
hapi21.3.1032379.030.425.77
microrouter3.1.332073.430.725.72
restify11.1.030820.431.975.56
fastify-big-json5.0.012205.681.42140.44
express5.0.010808.091.931.93
express-with-middlewares5.0.09815.5101.273.65
trpc-router10.45.2N/AN/AN/A

Documentation

The complete documentation is available here.

Support

CMMV is an open-source project, and we are always looking for contributors to help improve it. If you encounter a bug or have a feature request, please open an issue on GitHub.

Stay in Touch

License

CMMV is MIT licensed.

Keywords

FAQs

Package last updated on 09 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc