Dates

new Date()

This returns a current date time object. The what it displays depends on the environment and how you display it.

const now = new Date();
console.log("javascriptDate", now);
// This will show utc datetime object: javascriptDate 2025-06-10T11:35:24.046Z
console.log(`local date: ${now}`);
// This will show local datetime string: local date: Tue Jun 10 2025 13:35:24 GMT+0200 (Central European Summer Time)

Timezones

convert to another timezone only in string

const dateUsEastCoast = now.toLocaleString("en-US", {
  timeZone: "America/New_York",
});
console.log(`dateUsEastCoast: ${dateUsEastCoast}`);
// dateUsEastCoast: 6/10/2025, 7:35:24 AM

Ternary

Sequelize

source: https://sequelize.org/docs/v6/core-concepts/model-querying-finders/

common actions

  1. add row
const newCategory = await Category.create({
  keyword: keyword,
  category: category,
});
  1. delete row

  1. find row based on field name
const project = await Project.findOne({ where: { title: "My Title" } });
if (project === null) {
  console.log("Not found!");
} else {
  console.log(project instanceof Project); // true
  console.log(project.title); // 'My Title'
}

Schema

const { DataTypes } = require("sequelize");
const sequelize = require("./_connection");

const Category = sequelize.define(
  "Category",
  {
    keyword: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    category: {
      type: DataTypes.STRING,
      allowNull: false,
    },
  },
  {
    timestamps: false, // Disable createdAt and updatedAt
  }
);

module.exports = Category;

sqlite connection

const { Sequelize } = require("sequelize");
const path = require("path");

const sequelize = new Sequelize({
  dialect: "sqlite",
  // storage: path.join(__dirname, "../database.sqlite"), // Database file location
  storage: path.join(process.env.PATH_DB, "news_searcher.db"), // Database file location
  logging: false, // Disable logging
});

module.exports = sequelize;