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

@sabbatical/people-service

v0.2.1

Published

An example MEAN+TypeScript micro-service for People (Person data).

Downloads

5

Readme

A People Micro-Service based on Node.js, Angular2, and NativeScript

All code is in TypeScript!

This is a work in progress. All comments are welcome!

Tools and Environment Setup

See my setup-mean-ts instructions for Mac.

Technologies

This project uses:

| Tech | Name/Web-site | Version |--------|:---------|:---------| | | TypeScript | ~2.2.1 | | | Node.js | 6.9.1 | | | Angular2 | 2.1.2 | | | Express.js | 4.14.0 | | | MongoDB | 3.2.0 | | | NativeScript | 2.1.1 | | | Mocha | 3.0.2 | | | Protractor | 3.3.0 | | | Karma | 1.2.0 | | | npm | 3.10.8 | |

Overview

This project provides a working example of a complete, non-trivial data service, handling data describing individual people.

people-service includes:

  • a server that:
    • serves an Angular2 web-app
    • provides an API for managing the data
  • an Angular2 web-app for user access
  • database adaptors that plug-in, and are programmatically selectable, for:
    • a simple in-memory database for testing only
    • a MongoDB database, with mongoose data schema, for all persistent data use cases, including production
  • a mobile app for displaying data to a user
    This isn't public yet. I'm waiting until I have time to upgrade it to the latest version of NativeScript.
  • automated tests for:
    • the server
      • using mocha, internally, without a server running
      • externally, with a server running, via its API
    • database access
      • shared document-database-tests for:
        • in-memory database adaptor
        • MongoDB database adaptor
        • people-service (database access functions)
    • the web-app
      • ~~using Karma currently, this is broken, see notes below~~
    • end-to-end
      • using mocha
      • ~~using protractor currently, this is also broken, see notes below~~

This does not include:

  • user authentication
    See passport if you need authentication.

This template is nearly finished, and should be usable, for most micro-services. Just modify the data descriptions to make a new service.

Features

This micro-service:

  • [x] Uses TypeScript for the server, the browser, and for mobile
    making it easier to configure.
  • [x] Uses best-practices testing for server, client, and end-to-end.
    Uses mocha for the server, karma for the client, and protractor for end-to-end.
    :warning: karma for angular2 is broken as of v2.0.0-rc.5 and rc.6, and protractor has its share of problems See karma support will be added to quickstart
    and get help from Karma Gitter
  • [x] has a simple web UI using Angular2
  • [x] Uses npm scripts for (automated) building and testing.
    We used to use gulp, but it added a level of indirection, and still required much more work than the npm scripts that we use now.
  • [x] Uses the express micro-service framework on the server.
  • [x] has a mobile-app in NativeScript for Android and iOS
    This isn't public yet. I'm waiting until I have time to upgrade it to the latest version of NativeScript.
  • [x] stores its data in mongodb.
    mongodb is schema-less, and easy for development.
  • [x] automates deployment.
  • [x] Easily modified to use your specific document object type.
  • [x] Has a separate admin web-app.
    This will be added soon. It is working in another project, but must be migrated here.

Network Connections

Here's a sequence diagram showing how people-service fits into a system: Sequence Diagram

Setup for Build

This will take about 3 minutes:

npm install

Build

Build all of the software:

npm run build

Build a sub-project:

npm run build-browser-angular2
npm run build-server

Dependent Package Versions

All packages are pinned to specific versions. But all type delcarations through @types are allowed to upgrade up until the next major version. This is due to the tendency for corrections in type declarations, and we will probably lock these down for typings that are more reliable.

Test

Build and test all of the software:

npm run test

Build and test a sub-project:

  • Test the server internals standalone using mocha.
npm run test-server
  • Test the angular.js client in a Chrome browser using jasmine and karma.
    :warning: Karma testing doesn't work yet. See other notes.
npm run test-browser-angular2
  • Test the server from a Chrome browser using protractor with selenium.
npm run test-end-to-end-static
npm run test-end-to-end-live

Run the Service

npm run start-servers

This will start the server, with logs saved in the ./logs directory.

Stop the Service

npm run stop-servers

Exercise the Service

Note that these commands are similar to the ones in the automated end-to-end tests.

Use curl to create a Person record:

curl -H "Content-Type: application/json" -X POST -d '{"action":"create", "obj":{"name":{"given":"Sally","family":"Smith"}}}' http://localhost:3000/api/people

This command will return the created Person record, with its _id. Use this _id for your subsequent queries. In the examples below, the id was 5803c7396dc69c29557c92a5.

Use curl to read a Person

curl -H "Content-Type: application/json" -X POST -d '{"action":"read", "query":{"ids":["5803c7396dc69c29557c92a5"]}}' http://localhost:3000/api/people

Use curl to update a Person and then read back the updated Person

curl -H "Content-Type: application/json" -X POST -d '{"action":"update","query":{"conditions":{"_id":"5803c7396dc69c29557c92a5"}},"updates":[{"cmd":"set","field":"name.given","value":"Joe"}]}' http://localhost:3000/api/people

Use curl to delete a Person record and then confirm that read no longer returns that Person

curl -H "Content-Type: application/json" -X POST -d '{"action":"delete", "query":{"ids":["5803c7396dc69c29557c92a5"]}}' http://localhost:3000/api/people
curl -H "Content-Type: application/json" -X POST -d '{"action":"read", "query":{"ids":["5803c7396dc69c29557c92a5"]}}' http://localhost:3000/api/people

Use curl to find all of the Person records.

curl -H "Content-Type: application/json" -X POST -d '{"action":"find", "query":{"conditions":{}}}' http://localhost:3000/api/people

Exercise the Client

For now, it looks pretty much like the Angular2 Tour-of-Heroes tutorial:

The cloud instance on Joyent:

http://72.2.119.140:3000

Your local instance (for development):

http://localhost:3000

Problems

The tests use promisify-node, which has a bug when using es6 classes.
See: https://github.com/nodegit/promisify-node/issues/26

If you are developing this package, then run npm run patch-promisify-node after you run npm install.

This does not affect the generic-data-server package itself.

Deploy

You must first set up your cloud host machine manually on Joyent. These rough notes may help you.

After the host machine is setup, just run:

npm run deploy-production-to-joyent

Support

If you have any questions, suggestions, or problems, please email me at my address given on npm, or file an issue.