npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@syncthetic/rest-on-express

v1.0.3

Published

Easily build and manage a RESTful API using Express and MongoDB

Readme

RestOnExpress

Easily build and manage a RESTful API using Express and MongoDB.

Configuration settings are pulled from the environment.

| Environment Variable | Value | Default Value | |- | - | - | | ROE_DB_CONNECTION | <mongodb+srv://<username>:<password>@<host> | | | ROE_DB_NAME | <name of the datbase> | | | ROE_COLLECTIONS | <collection1:collection2:...> | | | ROE_PORT | <application listening port> | 3000 | | ROE_API_BASE | <the base reference to the API> | /api | | STANDALONE | boolean true if not an npm module | false |

Note that the first collection in the ROE_COLLECTIONS environment variable will be instantiated first. To use other collections in your resources, call the coll(name: string): collection method

Getting started as an NPM Module

Install the package npm i @syncthetic/rest-on-express --save import the package, set the route directory, and start the service

const restOnExpress = require('@syncthetic/rest-on-express/app')
restOnExpress.set_route_directory(__dirname + '/routes')
restOnExpress.start_api()

The route directory should point to the routes to be used via the Express app.

Getting started as repository

To get started, clone the repository git clone https://github.com/Syncthetic/RestOnExpress

Install dependant packages npm install

Set the environment variable ROE_STANDALONE to any value.

The API resources should be configured inside the routes/index.js file. Configure resources to point to the file which handles it's logic. These files should be stored and nested inside the /routes directory. I would encourage the use of descriptive path names.

// routes/index.js
router.use('/users', require('./users') // load routes/users/index.js
router.use('/user', require('./user')   // load routes/user/index.js

Since resources are in noun form, and can have singular and plural form associated with it, such as user and users resources, you may choose to have both singular and plural forms in one directory such as routes/users/plural.js and routes/users/singular.js

If your environment variables are set, start the API service with node app.js If desired, enter the environment variables when invoking the application

ROE_DB_CONNECTION="mongodb+srv://myusername:[email protected]" \
ROE_DB_NAME="orders" \
ROE_COLLECTIONS="products" \
node app.js

Sending API requests: http://localhost:<ROE_PORT>/<ROE_API_BASE>/<desired route path>

i.e, GET http://localhost:3000/api/users or PUT http://localhost:3000/api/user

Example for a simple user resource

// routes/user/index.js

var router = require('express').Router();

router.post("/", (request, response) => {
    collection.insertOne(request.body, (error, result) => {
        if(error) {
            return response.status(500).send(error);
        }
        response.status(201).send(result.result);
    })
})

// GET /api/user/:id
router.get("/:id", (request, response) => {
    collection.findOne({ "userId": request.params.id }, (error, result) => {
        if(error) {
            return response.status(500).send(error);
        }
        response.send(result.result);
    })
})

// PUT /api/user/:id
router.put("/:id", (request, response) => {
    collection.updateOne(
        { "userId" : request.params.id },
        { $set: request.body },
        { upsert: true},
        (error, result) => {
            if (error) { return response.status(500).send(error) }
            if (result.result.nModified === 1 && result.result.n === 1) response.status(200).send(result.result)
            else if ( result.result.upserted ) response.status(201).send(result.result)
            else if (result.result.n === 1 && result.result.nModified === 0 ) response.status(304).send(result.result)
        }
     )
})

// DELETE /api/user/:id
router.delete("/:id", (request, response) => {
    collection.deleteOne({ "userId": request.params.id }, (error, result) => {
        if(error) {
            return response.status(500).send(error);
        }
        response.send(result.result);
    })
})

module.exports = router;