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

create-sojeb-express-ts-app

v3.0.7

Published

Boilerplate to create a new express typescript project

Downloads

7

Readme

create-sojeb-express-ts-app

A productive Boilerplate to create new Express typescript project.

Example :

https://github.com/SojebSikder/nodejs-ecommerce

Getting started

Creating a new app

Using yarn :

yarn create sojeb-express-ts-app hello-world

Try changing example.controller.ts file in app directory.

@Controller()
export class ExampleController {
  @Get("", { middleware: [decorateHtmlResponse()] })
  index(req: Request, res: Response) {
    res.render("index");
  }
}

Configure

  • Set up database credentials in env file
  • Migrate database using this command: yarn prisma migrate dev

Installing

yarn install

Production

  • Build yarn build
  • Running yarn start:prod

Development

  • Run: yarn start

  • Watch changes: yarn start:dev


Table of contents (incomplete docs)


Overview

Controllers

Controllers is used to handling requests and reponses. We use classes and decorators to create basic controllers. Decorators associate classes with required metadata to create routing map.

Routing

In following example we will we'll use the @Controller() decorator, which is required to define a basic controller. We'll specify an optional route path prefix of example. Using a path prefix in a @Controller() decorator allows us to easily group a set of related routes, and minimize repetitive code. For example, we may choose to group a set of routes that manage interactions with a customer entity under the route /customers. In that case, we could specify the path prefix customers in the @Controller() decorator so that we don't have to repeat that portion of the path for each route in the file.

@Controller("/example/")
export class ExampleController {
  @Get()
  index(req: Request, res: Response) {
    res.send("Hello world");
  }
}

HINT: To create a controller using the CLI, simply execute the yarn cmd make:controller example command.

Techniques

Storage

local

We need to config first to use Local storage

import { Storage } from "../../system/src";
import { Module } from "../../system/src/core/decorator";
import { ExampleController } from "./example/example.controller";

@Module({
  imports: [
    Storage.config({
      driver: "local",
      connection: {
        // Set public directory here
        rootUrl: "public",
      },
    }),
  ],
  controllers: [ExampleController],
})
export class AppModule {}

And we are ready to upload files to s3 bucket. To upload files, here is the basic example:

  // import { Storage } from "../../../system/src";
  public async upload() {
    await Storage.put("sojebdemo/test.txt", "Hello world");
  }

We can get url from bucket using Storage.url('fileName').

  // import { Storage } from "../../../system/src";
  public async getFileUrl() {
    return Storage.url("sojebdemo/test.txt");
  }

If we want to read files:

  // import { Storage } from "../../../system/src";
  public async getFile() {
 return Storage.get("sojebdemo/test.txt");
  }

Now If we want to delete files:

  // import { Storage } from "../../../system/src";
  public deleteFile() {
    return Storage.delete("sojebdemo/test.txt");
  }

aws s3

To use aws S3 first we need to config in app.module.ts:

import { Storage } from "../../system/src";
import { Module } from "../../system/src/core/decorator";
import { ExampleController } from "./example/example.controller";

@Module({
  imports: [
    Storage.config({
      driver: "s3",
      connection: {
        awsAccessKeyId: "...",
        awsSecretAccessKey: "...",
        awsBucket: "...",
        awsDefaultRegion: "ap-southeast-1",
      },
    }),
  ],
  controllers: [ExampleController],
})
export class AppModule {}

And we are ready to upload files to S3 bucket. To upload files:

  // import { Storage } from "../../../system/src";
  public async upload() {
    await Storage.put("sojebdemo/test.txt", "Hello world");
  }

We can get url from bucket using Storage.url('fileName').

  // import { Storage } from "../../../system/src";
  public async getFileUrl() {
    return Storage.url("sojebdemo/test.txt");
  }

If we want to read files from S3 we have to use S3Adapter. And pass Storage config in S3Adapter constructor.

  // import { Storage } from "../../../system/src";
  // import { S3Adapter } from "../../../system/src/core/Disk/drivers/S3Adapter";
  public async getFile() {
    const s3Adapter = await new S3Adapter(Storage.getConfig()).get(
      "sojebdemo/test.txt"
    );

    s3Adapter.on("data", function (data) {
      console.log(data.toString());
    });
  }

Now If we want to delete files from S3 we can use Storage class again.

  // import { Storage } from "../../../system/src";
  public deleteFile() {
    return Storage.delete("sojebdemo/test.txt");
  }

Mail

For sending email, nodemailer used under the hood. So first config Mail in app.module.ts. Change the app.module.ts like this:

import { env, Mail } from "../../system/src";
import { Module } from "../../system/src/core/decorator";
import { ExampleController } from "./example/example.controller";

@Module({
  imports: [
    Mail.config({
      connection: {
        host: env("MAIL_HOST"),
        from: {
          address: env("MAIL_FROM_ADDRESS", "[email protected]"),
        },
        secure: false,
        port: env("MAIL_PORT", 587),
        username: env("MAIL_USERNAME"),
        password: env("MAIL_PASSWORD"),
      },
    }),
  ],
  controllers: [ExampleController],
})
export class AppModule {}

Now to send a basic email we can do like this:

  /**
   * send mail
   */
  public async sendMail() {
    Mail.to("[email protected]").body("Hello world").send();
  }

CLI

Overview

We can automate process using cmd cli.

  • generate controller and service together: yarn cmd make:module Blog
  • generate only controller: yarn cmd make:controller Blog
  • generate only service: yarn cmd make:service Blog
  • To see all available commands: yarn cmd list

Technology used

  • Typescript
  • Node.js
  • Express
  • Prisma
  • Mysql
  • redis
  • Nodemailer
  • Jest
  • jwt
  • graphql etc.

Contribute


If you want to contribute fork the repo, create new branch and make pull request.

Setup (Contributing)

If you clone this repo then you have to setup these things manually.

  • Copy .env.example to .env And set up database credentials in env file
  • Migrate database using this command: yarn prisma migrate dev

For help and support

Email: [email protected]

Issue

If you find any problem please create an issue.