Node.js Fastify API Boilerplate

JS
S
JavaScript

Starter template for building high-performance Node.js APIs with Fastify framework. Includes basic setup, routing, and best practices for rapid development.

1import { DataTypes, Sequelize } from "sequelize";
2
3const dbUser = process.env.dbUser;
4const dbUserPass = process.env.dbUserPass;
5const dbName = process.env.dbName;
6
7const sequelize = new Sequelize(
8  `postgres://${dbUser}:${dbUserPass}@localhost:5432/${dbName}`,
9  {
10    logging: false,
11    pool: {
12      max: 10,
13      min: 10,
14    },
15  },
16);
17await sequelize.authenticate();
18
19const ShortenedUrl = sequelize.define("shortenedurl", {
20  id: {
21    type: DataTypes.STRING,
22    primaryKey: true,
23  },
24  srcurl: DataTypes.STRING,
25  created: DataTypes.DATE,
26  lastaccessed: DataTypes.DATE,
27}, {
28  timestamps: false,
29});
30
31export async function save(id, srcUrl) {
32  await ShortenedUrl.create({
33    id,
34    srcurl: srcUrl,
35    created: new Date(),
36    lastaccessed: new Date(),
37  });
38  return true;
39}

Created on 11/6/2023