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

generator-simple-node

v0.5.0

Published

NodeJs API generator

Downloads

2

Readme

Simple-Node

Simple-Node is a yeoman generator for rapid protopyping & scaffolding a nodejs + express API.

Technologies

  • https://nodejs.org/ - Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.
  • https://expressjs.com/ - Fast, unopinionated, minimalist web framework for Node.js
  • https://sequelize.org/ - Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication and more.
  • https://jwt.io/ - JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.
  • and more soon!!

Installation & Usage

Install the generator

$ npm install -g yo
$ npm install -g generator-simple-node

For create an App run :

$ yo simple-node project_name
$ cd project_name 
$ npm install or yarn install

The generated project shuld look like this :

,-- src
|   |-- config
|   |   `-- config.js
|   |-- controllers
|   |   |-- UserController.js
|   |   `-- AuthController.js
|   |-- models
|   |   `-- User.js
|   |-- services
|   |   `-- UserService.js
|   |-- routes
|   |   |-- UserRoutes.js
|   |   `-- AuthRoutes.js
|   |-- db
|   |   |-- migrations
|   |   |  `-- create-user.js
|   |   `-- index.js
|   `-- utils
|       |-- AuthUtils.js
|       `-- Utils.js
|-- .env
|-- .gitignore
|-- .babelrc
|-- .sequelizerc
|-- package-lock.json
|-- package.json
`-- README.md

To Start the server run :

  • this command shuld start the server on port 3009 and create an in-memory DB
$ npm run dev

Then you can POST a user with this body :

{
    "username": "demouser",
    "password": "demopassword"
}

To this route:

localhost:3009/api/v1/users

Then you can retrieve all the users , with a GET request to the same route.

Use the scaffold sub-generator

This subgenerator is used to create a model and his corresponding Controller , Service , Route and Sequelize Migration

For create a scaffold use:

  • The model name is required
yo simple-node:scaffold Modelname

This command shuld generate :

 src
   |-- controllers
   |   `-- ModelnameController.js
   |-- models
   |   `-- Modelname.js
   |-- services
   |   `-- ModelnameService.js
   |-- routes
   |   `-- ModelnameRoutes.js
   |-- db
      `-- migrations
          `-- create-modelname.js

Next you need to link the generated routes to the app:

  • This step is gonna be automaticaly generated in an upcomming version

On the app.js add:

import newModelRoutes from './routes/Modelname';

and

app.use('/api/v1/modelnames', newModelRoutes);

With this you can use your generated model API

GET localhost:3009/api/v1/modelnames
GET localhost:3009/api/v1/modelnames/:id
POST localhost:3009/api/v1/modelnames
PUT localhost:3009/api/v1/modelnames/:id
DELETE localhost:3009/api/v1/modelnames/:id

To secure a route with jwt authentication

in the app.js file add the AuthUtils validateJwtToken method as middelwares to the route

Example: in app.js

import authUtils from './utils/AuthUtils';
app.use('/api/v1/todos', authUtils.validateJwtToken , newModelRoutes);

With this changes if go to the todos GET (localhost:3009/api/v1/todos) if you dont pass a valid token in the Authorization headers, the server shuld give you a 401 unauthorized

To get a valid token for secure routes you shuld use this route passing a previusly created username & password

POST localhost:3009/api/v1/authorization/login

Todos

  • Dockerize the app
  • Testing with Jest
  • Mailing
  • Reset password flow
  • Automate deploy
  • Circle CI (or another CI/CD tool)
  • and much more!!!

License

MIT © Jonathan Ramirez

Free Software, Hell Yeah!