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

@wearemanic/express-base

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wearemanic/express-base

Common/shared configuration for Express.

  • 1.0.4
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

@wearemanic/express-base

Common/shared configuration for Express & MongoDB.

Installation

npm install --save @wearemanic/express-base

Usage

import { config } from 'dotenv';
import createApp from '@wearemanic/express-base';
import * as schemas from './schemas/index.js';

config();

createApp({ env: process.env, schemas }).listen(3000)

Configuration

The following configuration is available:

import { config } from 'dotenv';
import createApp from '@wearemanic/express-base';
import fs from 'fs'
import path from 'path'
import * as url from 'url'
import * as schemas from './schemas/index.js';

config();

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

const options = {
  env: process.env,
  staticDirectory: path.resolve(__dirname, '../dist'),
  apiRoot: '/api',
  trustProxy: true,
  httpsRedirect: true,
  middleware: {
    cors: {
      origin: '*'
      ...
    },
    morgan: {
      format: 'combined',
      options: { ... }
    },
    json: {
      limit: '50mb',
      ...
    }
  },
  schemas: { ... }
}

createApp(options).listen(3000)

Model / Collection / Route Creation

createApp accepts a schema definition object (schemas), which it then uses to dynamically create MongoDB collections for each datatype. After instantiating each collection, it then generates API endpoints for managing them.

import { config } from 'dotenv';
import createApp from '@wearemanic/express-base';

config();

const User = {
  name: 'String',
  email: 'String',
  age: 'Number'
}

const Session = {
  user: {
    type: 'ObjectId',
    ref: 'User'
  },
  location: 'Mixed'
  date: {
    type: 'Date',
    default: Date.now
  }
}

createApp({ 
  env: process.env,
  schemas: { User, Session }
}).listen(3000)

The above will generate the following routes:

Collection: USER

GET    : `/api/users`
GET    : `/api/users/:id`
POST   : `/api/users`
PUT    : `/api/users/:id`
DELETE : `/api/users/:id`

Collection: SESSION

GET    : `/api/sessions`
GET    : `/api/sessions/:id`
POST   : `/api/sessions`
PUT    : `/api/sessions/:id`
DELETE : `/api/sessions/:id`

Keywords

FAQs

Package last updated on 09 Nov 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