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

nextjs-starter-server

v0.0.4

Published

Nextjs-starter-server back end built with NestJS and TypeScript

Downloads

8

Readme

Description

The dedicated back end for the nextjs-starter-server project.

main

Technologies Leveraged

  • Eslint
  • Husky
  • Jest
  • NestJS
  • nestjs-pino
  • Node
  • Passport
  • Prettier
  • TypeScript
  • Webpack (to enable Hot Module Replacement)
  • Swagger
  • Serve-static
  • Prisma

alt text

Prerequisites & Package Management

Dependencies for this project managed via npm. Ensure you have npm and Node installed. This project uses Node v14.17.3 (LTS) and npm v7.19.1.

If you are on a unix based system, you can use nvm to install specific node versions using nvm install 14.17.3, followed by nvm alias default 14.17.3.

Local Setup

  • Clone this repository
  • Setup the environment variables

For a reference of available environment variables, see the .env.sample file. The environment variables are:

| Variable | Description | | ------------------ | ----------------------------------------- | | NESTJS_PORT | Server port for NestJS | | PINO_LOG_LEVEL | Property for desired pinojs logging level | | NODE_ENV | Specifies the environment | | SWAGGER_PASSWORD | Password to log into swagger ui on /docs | | SWAGGER_USER | Username to log into swagger ui on /docs | | DATABASE_URL | Connection string for database |

Installation

$ npm install

Running the server

During local development, it's recommended that you run the npm run start:dev command to take advantage of Hot Module Replacement, as well as the automatic TypeScript generation. This allows you to avoid having to re-run the build command after you make a change to see the latest version of the application.

The default NESTJS_PORT provided in the .env.sample file points to port 8000. You can navigate to localhost:8000/api to verify that the server is running properly.

# development
$ npm run start

# watch mode with HMR
$ npm run dev

# production mode
$ npm run start:prod

Running the tests

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

NestJS CLI

Due to the fact that we are using the NestJS framework to build out the server-side application, it is recommended to install the NestJS CLI so that you can quickly generate new resources, controllers, etc. after becoming familiar with the NestJS API. To install the NestJS CLI globally, run the following command npm install -g @nestjs/cli.

For example, to quickly spin up a new resource or controller, you can use the following commands within the appropriate pod directory (i.e src/podName).

Generate a controller class:

nest g controller <insert-controller-name-here>
nest g module <insert-module-name-here>
nest g service <insert-module-name-here>

Generate a resource:

nest g resource <insert-resource-name-here>

For more information on the NestJS CLI and its available commands, please refer to the documentation.

Swagger API Documentation

You can view the Swagger UI at http://localhost:<NESTJS_PORT>/docs. If you'd like to view the JSON format of the API documentation, you can go to http://localhost:<NESTJS_PORT>/docs-json.

For all environments except production, you can view the Swagger API documentation at URL/docs using the SWAGGER_USER AND SWAGGER_PASSWORD env variables.

For more information on how the SwaggerModule is used in NestJS, please refer to the documentation.

Important Note: reflect-metadata must be installed otherwise you will get the following error: Error "@nestjs/swagger" plugin could not be found!

Automatic TypeScript Generation

If you are using the npm run start:dev command, this project automatically generates TypeScript definitions using the openapi-typescript package.

We are generating the OpenAPI JSON schema file using the @nestjs/swagger package. The JSON file outputs to the ./swagger directory and automatically updates based on changes to NestJS Controllers, DTOs, and Entitys. Once this api.json file changes, we automatically generate the types.ts file present in the ./generated-typescript directory.

For more information on openapi-typescript, please refer to the documentation.

Note: if you are not using the start:dev command, you need to manually run the npm run generate-types command.

Note: We are using lint-staged on this project. As a result, we don't necessarily need to have prettier configured in our respective editors. lint-staged will take care of any auto formatting for you via the Husky pre-commit hook.

Initialize the Database and Apply Migrations

For the database setup, you must initialize Prisma with the following command:

npx prisma generate

The above command will connect to the database specified in DATABASE_URL, pulling from your local .env file. Make sure to include the Postgres username, password, and database name where appropriate.

npx prisma generate loads the Prisma schema from prisma/schema.prisma.

To create local postgres database, download the Postgres App and create a server. For more convenient management, you can use clients such as Postico or DBeaver. Alternatively, you can use the Postgres CLI command psql directly to create a new database.

Creating a migration with a specific name, use the generate:prisma-migration to create and apply the migration. If you want to preview the migration before applying, use the create:prisma-migration.

$ npm run generate:prisma-migration -- name-of-migration

// Create only
$ npm run create:prisma-migration -- name-of-migration

If you can use help with your React project or have a burning question, or an issue in your project that needs help with, I invite you to hire me as your Coach. My strategy is 100% results-oriented. If you want to sample how I work 1-on-1, let’s schedule a one-time deep dive Consultation. Additionally, I will tutor you in react, javascript, typescript, mongodb, node, d3.

Where to go from here?

If you like this library, don't be shy to star it!