Skip to content

Instantly share code, notes, and snippets.

const Sequelize = require(‘sequelize’);
const sequelize = new Sequelize(
"nama_database",
"username",
"password",
{
//contoh
host: "localhost",
dialect: "mysql" | "sqlite" | "postgres" | "mssql"
}
// models/Movie.js
const Sequelize = require("sequelize")
const sequelize = require("../config/db")
const Movie = sequelize.define(
"movie",
{
id_movie: {
type: Sequelize.INTEGER,
primaryKey: true,
// controllers/movieController.js
const Movie = require("../models/Movie")
module.exports = {
index: function(req, res) {
Movie.findAll().then(function(rows) {
res.render("movie/index", { data: rows })
})
},
// definisikan dependency yang dibutuhkan
const express = require("express");
const app = express();
const multer = require("multer");
//untuk menambahkan path
const path = require("path");
// menentukan lokasi pengunggahan
const diskStorage = multer.diskStorage({
destination: function (req, file, cb) {
const book = {
"title": "Manusia Setengah Salmon",
"author": "Raditya Dika",
"publisher": {
"name": "Gagas Media",
"address": "Jakarta Selatan"
}
}
const title = book.title;
const book = {
"title": "Manusia Setengah Salmon",
"author": "Raditya Dika",
"publisher": {
"name": "Gagas Media",
"address": "Jakarta Selatan"
}
}
// destructuring
const student = [
{ id: 11, name: "Smith" },
{ id: 12, name: "Roger" },
{ id: 13, name: "Romeo" },
{ id: 14, name: "Jesicca" },
{ id: 15, name: "Ellen" }
];
// // what we need ['smith', 'Roger', 'Romeo', 'Jesicca','Ellen']
{
"type":"prepaid",
"productCode": "AXIS25",
"productName": "Axis 25.000",
"productType": "mobile"
}
const books = [
{
title: "Sebuah Seni Untuk Bersikap Bodo Amat",
author: "Mark Manson"
},
{
title: "Segala - galanya Ambyar",
author: "Mark Manson"
},
{
// for loop
var numbers = [10, 20, 30, 40];
var sum = 0;
for (var i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
console.log(sum); // hasilnya adalah 100