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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ne-data

v1.9.4

Published

description

Downloads

7

Readme

ne-data (Node Engine Data)

A quick and simple way to create a structured restAPI using, NodeJS, MongoDB and Mongoose.

Snippit from the Server file

Just add this code and it will automatically add any additional files you place in the api folder. the route for the api will be domain.com/apiPath/filename

where

  • apiPath is the apiPath you set in the server file
  • filename is the name of the file in the api folder

var neData = require('ne-data');

var dirName = __dirname;
var apiPath = "/api";
neData.server(server, dirName, apiPath);

Sample API file

Define the schema in any way you want and create as many as you want.

These files need to be in a folder matching the apiPath you provides in the same directory as the server file


var router = require('express').Router();
var mongoose = require('mongoose');
var neData = require('ne-data');

var pageSchema = {
    path:{type: String, required: true},
    title:{type: String, required: true},
    description:{type: String, required: true},
    pd:{
        pdNumber:{type: Number, required: false, default: '0'},
        pd1:{
            path: {type: String, required: false}
        }
    },
    createdAt:{type: String, required: true}

};

var Model = mongoose.model(
    'Page',
    pageSchema,
    'page');


neData.model(router, Model);


module.exports = router;

API Features

Post The entire request body becomes the object that is posted

Get Get by Id Get with Limit results to number Get with Limit and cycle

Put Put by Id

Delete Delete by Id

Use query field value pairs find specific documents http://localhost:3001/api/page?f1=pathField&v1=pathFieldValue

  • get will get the document where the pathField matches the pathFieldValue
  • delete will delete the document where the pathField matches the pathFieldValue
  • put will edit the document where the pathField matches the pathFieldValue, two addidional query params are needed to give the field you want to edit and the new value for the that field

If you are interested in more details on the working of the api please ask.

Steps

  1. Connect to mongoDB using mongoose
  2. Require and NPM install the dependencies
  3. Define your schema using mongoose syntax
  4. Use the schema to create a Model
  5. Activate neData by calling neData.init(router, Model)

POST

Add a document to a collection

post request

  • http://localhost:3001/api/people

where

  • people = name of the model/collection
  • req.body = the document you want to add
  • example req.body
{
  "firstName": "John",
  "lastName": "Jackson",
  "email": "[email protected]"
}

results

  • Adds the contents of the req.body as a document to the people collection using the mongoose schema.

comments

  • Example post req with Json body using Postman.

Post Example using postman

GET

Get all in collection

get request

  • http://localhost:3001/api/people

where

  • api = the apiPath you specified
  • people = name of the model/collection

results

  • all documents in the people collection

Limit the request to a a number of documents

get request

  • http://localhost:3001/api/people?limit=3

where

  • api = the apiPath you specified
  • people = name of the model/collection
  • query: limit = the number of documents you want

results

  • the first 3 documents in the people collection

Cycle through docs in the collection

get request 1

  • http://localhost:3001/api/people?limit=3&batch=1

where

  • api = the apiPath you specified
  • people = name of the model/collection
  • query: limit = the number number of documents in a cycle
  • query: batch = the cycle number

results

  • the 1st, 2nd and 3rd document in the collection

get request 2

  • http://localhost:3001/api/people?limit=3&batch=2

where

  • api = the apiPath you specified
  • people = name of the model/collection
  • query: limit = the number number of documents in a cycle
  • query: batch = the cycle number

results

  • the 4th, 5th and 6th document in the collection

get request 3

  • http://localhost:3001/api/people?limit=3&batch=3

where

  • api = the apiPath you specified
  • people = name of the model/collection
  • query: limit = the number number of documents in a cycle
  • query: batch = the cycle number

results

  • the 7th, 8th and 9th document in the collection

Search for documents where a field matches a value

get request

  • http://localhost:3001/api/people?f1=firstName&v1=John

where

  • api = the apiPath you specified
  • people = name of the model/collection
  • query: f1 = the field you want to search by
  • query: v1 = the value in the f1 filed you are looking to match

results

  • all documents in the people collection where the firstName field is John

comments

  • the search in case sensitive, so if you type john instead og Johh it will not find it.

Get one document in a collection using the document _id

get request

  • http://localhost:3001/api/people/55eefa231c0eba0d2c72af40

where

  • api = the apiPath you specified
  • people = name of the model/collection
  • 55eefa231c0eba0d2c72af40 = the _id of the document you want

results

  • The document with the _id of 55eefa231c0eba0d2c72af40

PUT

Search for documents where a field matches a value and give a new value to a field in those documents

put request

where

  • api = the apiPath you specified
  • people = name of the model/collection
  • query: f1 = the field you want to search by
  • query: v1 = the value in the f1 filed you are looking to match
  • query: fs1 = the field you want to edit
  • query: vs1 = the new value for the field you want to edit

results

  • all documents in the people collection where the firstName field is John gets given a new value of [email protected] for the email field

comments

  • the search in case sensitive, so if you type john instead og Johh it will not find it.
  • you can search by one field and edit another field
  • if more than one document matches the search then all those documents will be updated
  • By default only one document is edited if you want to edit all documents matching the query then at a query param called multi=yes (?multi=yes or &multi=yes)

Search for documents where a field matches a value and use a json request body object to update the fields

put request

  • http://localhost:3001/api/people?f1=firstName&v1=John

where

  • api = the apiPath you specified
  • people = name of the model/collection
  • query: f1 = the field you want to search by
  • query: v1 = the value in the f1 filed you are looking to match

results

  • all documents in the people collection where the firstName field is John

comments

  • See the MongoDB docs on how to format the json req body (http://docs.mongodb.org/manual/reference/method/db.collection.update)

  • By default only one document is edited if you want to edit all documents matching the query then at a query param called multi=yes (?multi=yes or &multi=yes)

  • for


{
  "_id": "55eefa231c0eba0d6c72af40",
  "firstName": "John",
  "lastName": "Jackson",
  "email": "[email protected]",
  "detail": {
            "thing": "thing value"
          },
  "__v": 0,
  "createdAt": "Fri Sep 18 2015 17:09:51 GMT+0200 (SAST)"
}
  • use this reg body object to define what to edit

{
  "detail.thing": "new thing value",
  "email": "[email protected]"
}
 

Search for documents by _id and use a json request body object to update the fields

put request

  • http://localhost:3001/api/people/55eefa231c0eba0d6c72af40

where

  • api = the apiPath you specified
  • people = name of the model/collection
  • 55eefa231c0eba0d6c72af40 = the _id of the document you want to edit

results

  • all documents in the people collection where the firstName field is John

comments

  • See the MongoDB docs on how to format the json req body (http://docs.mongodb.org/manual/reference/method/db.collection.update)

  • By default only one document is edited if you want to edit all documents matching the query then at a query param called multi=yes (?multi=yes or &multi=yes)

  • for


{
  "_id": "55eefa231c0eba0d6c72af40",
  "firstName": "John",
  "lastName": "Jackson",
  "email": "[email protected]",
  "detail": {
            "thing": "thing value"
          },
  "__v": 0,
  "createdAt": "Fri Sep 18 2015 17:09:51 GMT+0200 (SAST)"
}
  • use this reg body object to define what to edit

{
  "detail.thing": "new thing value",
  "email": "[email protected]"
}
 
 

DELETE

Remove a document from a collection using a field value combination

delate request

  • http://localhost:3001/api/people?f1=firstName&v1=John

where

  • people = name of the model/collection
  • api = the apiPath you specified
  • query: f1 = the field you want to search by
  • query: v1 = the value in the f1 filed you are looking to match

results

  • remove documents in the people collection where the firstName field is John

comments

  • the search in case sensitive, so if you type john instead og Johh it will not find it.

Remove one document in a collection using the document _id

delete request

  • http://localhost:3001/api/people/55eefa231c0eba0d2c72af40

where

  • people = name of the model/collection
  • 55eefa231c0eba0d2c72af40 = the _id of the document you want to remove

results

  • The document with the _id of 55eefa231c0eba0d2c72af40 is removed

dataRef

Example dataRef object


var dataRef = {
    "name": "emails",
    "slug": "/admin/emails",
    "apiSlug": "/data/emails",
    "interfaceType": "default",
    "cycleByDefault": false,
    "batchSize": 10,
    "type": "noEdit",
    "categories": ["undefined"],
    "tags": [],
    "fields": [
        {
            name: "p1",
            data: "nameFirst",
            type: "noEdit"
        },
        {
            name: "p2",
            data: "nameLast",
            type: "noEdit"
        },
        {
            name: "p3",
            data: "email",
            type: "noEdit"
        },
        {
            name: "p3",
            data: "user",
            type: "ObjectId"
        }
    ]
};

Field Display types

This is used when displaying data in this field

displayType: "string"

  • This field contains a string
  • This is the default
  • Not not need to add this it is assumed that a field is a string unless otherwise specified

displayType: "ObjectId"

  • this field is the object id of another document in another collection

displayType: "array"

  • this field is an array of strings

Field Edit types

This is used when editing data in this field

editType: "text"

  • This fieled contains a string
  • This is the default
  • Not not need to add this it is assumed that the field can be edited with a text input

editType: "noEdit"

  • can not edit this field in ne-admin

editType: "select"

  • Select the value of this field from a list of values
  • if this edit type is specified the editOptions array must also be provided
  • selectOptions: ["option1", "option2"]

editType: "textarea"

  • The user is given a textarea instead of a text box to edit the field.

editType: "html" (Future feature)

  • The user is given a html area instead of a text box to edit the field.

editType: "" (Future feature)

  • The user is given a html area instead of a text box to edit the field.

License

The MIT License (MIT)

Copyright (c) 2015 Bernard Hamann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.