Dates
new Date()
This returns a current date time object. The what it displays depends on the environment and how you display it.
- the object has the utc and all timezones as properties at the same time
- do not trust the object, only the strings that are made from it are really reliable
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
<true/false> ? <if true> : <if false><true/false> @@ <if left if TRUE this occurs><true/false> || <if left if FALSE this occurs>
Sequelize
source: https://sequelize.org/docs/v6/core-concepts/model-querying-finders/
common actions
- add row
const newCategory = await Category.create({
keyword: keyword,
category: category,
});
- delete row
- 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;