Showing posts with label pemrograman web. Show all posts
Showing posts with label pemrograman web. Show all posts

Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 3)

July 10, 2019 Add Comment


I am really excited to write about this part because in this part we are gonna learn to write code for creating CRUD using Node js, Express, Mongodb and Bootstrap. And of course, as this tutorial is created for beginner, I am going to make sure that you guys can understand every piece of code that I am going to write by explaining them.

1. First Initialisation for Node.js project
First we have to open console/cmd/command prompt. Make sure that the path of directory for the project is correct. Let's say that our project name will be "project_note".

Okay, after that wee need to initialise the project, just to tell the system that we are going to use node js and use npm for the node package management, then write 
npm init

Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 3)
npm init

The use of npm init is mainly just to make dependency file.
Open the project folder using your favourite editor. I recommend you to use Visual studio code. 
As we can see, json is now already initiated.

2.Once done, still in the console write 
npm install express

Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 3)
npm install express

this code means that we are using npm (node package management) to install node module called 'express'.

What is express in Node ?
Express is designed for building web applications and APIs with NodeJs. So, Express will help us to develop web application.
3. then we write
npm install nodemon

Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 3)
npm install nodemon

What is nodemon module in Node js ?

nodemon is a node module that allow us to run the system continuously. So, if we make a change in the file project, we don't need to restart to run the project. Because nodemon will automatically run it for us. Therefore, it is a very very useful module for developer.


now we can see in the json file that express and nodemon have already installed.

Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 3)
packae.json in vs code

Now, we just need to change the start value to

So, every time we start the project, it will automatically start using nodemon.
"start": "nodemon app.js"

Okay, it's quite simple right ? Yes it is! (i hope so)

4. Let's install other important modules for the development. We are going to install ejs, mongoose, and dotenv modules. These things are familiar for you ? dont't worry I will explain it all to you.

What is ejs ?
Ejs is the short of Embedded JavaScript templating. EJS is a simple templating language that lets you guys as developers to generate HTML markup with plain JavaScript. Where to put Ejs? as it is a template formatting, we will put in the HTML file but, of course, with a tag like this
<% html_script %>

I am going to explain it later.

What is mongoose ?
according to www.freecodecamp.org, Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node.js. It manages relationships between data, provides schema validation, and is used to translate between objects in code and the representation of those objects in MongoDB.

So, Mongoose is used only if we are going to use Mongodb database for our application. Where the mongodb module is a library that can enable node js to connect with mongodb.

What is dotnev ?
Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env. So, dotnev will help us to secure our data which is needed for developing web applications like API_key, database password and database username.

Now lets install it
you can install like this
npm install dotnev mongoose ejs


or one by one like this
npm install dotnev

npm install mongoose

npm install ejs


Ok, I think it is enough for this article, in the next article we are going to create the real Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 4).

Table Content

title Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 1 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 2 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 3 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 4 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 5 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 6 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 7 Link


Tag :
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Express, Mongodb and Bootstrap For Beginner

Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 2)

June 29, 2019 Add Comment
After we learned a little bit to know about Node Js / Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 1) , today, in this article we are going to learn how to install Node Js

Installing Node Js | Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 2)

Well,again again.. as we are now going to learn how to install Node JS, If you don't know what node.js is, you guys can read my article about Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 1). If you already know and maybe you are interested in trying js nodes then we will install it on windows.

1. Download Node.JS Installer on the official website at https://nodejs.org/download/
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 2)
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 2)
I fully recommend you to download the LTS version which is also recommended by node team for most users.
2. Run the downloaded msi file.
3. Follow the instructions and User Agreement. And wait until the installation is complete
4. Now you restart your computer.

If you have followed the steps above, NodeJS is now installed. To check, you can open a command prompt, and type the following code :
To see the version of the node that is installed :
node -v

to see which version of npm is installed:
npm -v

Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 2)
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 2)


Ok, that's the tutorial to install Node js in our computer. Now lets part to the part 3 and we are gonna be learning how to Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner (Part 2)


Table Content

title Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 1 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 2 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 3 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 4 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 5 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 6 Link
Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap Part 7 Link

Tag : Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner, Express, Mongodb and Bootstrap For Beginner, Creating Simple CRUD Using Node js, Express, Mongodb and Bootstrap For Beginner

Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh

January 09, 2016 Add Comment
Assalamualaikum ... saat ini saya akan membahas sedikit tentang Perbedaan Include, Require dan Require Once Pada PHP yang lengkap Dengan Contohnya dimana ini merupakan tugas yang saya dapatkan saat menempuh pelajaran Pemrograman Web di semester 5.

INCLUDE 

pengertian Include dalam PHP merupakan kemampuan PHP untuk menyertakan file PHP lainnya kedalam sebuah program PHP.

Fungsi :
1. Include akan menyertakan dan mengevaluasi seluruh program yang ada di file yang disertakan.
2. Jika terdapat error pada program yang disertakan, maka error akan ditampilkan di layar.
3. Jika file yang disertakan ternyata tidak ditemukan (mungkin karena lokasi yang salah atau file tidak ada), maka program selanjutnya (setelah include) akan tetap dijalankan walaupun ditampilkan error.

Contoh dalam menggunakan Include dalam PHP


Membuat 2 program, yang pertama adalah program file php untuk koneksi ke database sedangkan yang satunya untuk file yang berfungsi untuk pemanggiilan file php koneksi.

Langkah-langkah: 
  • PERCOBAAN 1 : Membuat file koneksi dan memeriksa koneksi dengan nama koneksi_percobaan.php dengan script seperti di bawah ini ... kemudian ditampilkan hasilnya setelah di panggil.
    Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh
    percobaan 1
  • PERCOBAAN 2 : membuat file php untuk memanggil file koneksi_percobaan.php melalui file baru dengan perintah include .. 
    Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh
    percobaan 2
    Ketika memanggil melalui include, maka akan tampil error namun peritah selanjutnya akan tetap di jalankan. Seperti ditunjukkan di atas.

REQUIRE

Keterangan atau pengertian tentang Require : 
- Perintah require sebenarnya sama dengan perintah include.
- Bedanya hanya ketika pada saat file yang dikaitkan tidak ditemukan, maka perintah atau script selanjutnya tidak akan dijalankan.

Contoh program dan pengeksekusiannya
Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh, Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh, Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh
contoh require
Jika perintah menggunakan require dan program koneksi.php tidak ditemukan (lokasi folder sengaja di ubah), maka perintah selanjutnya yaitu menampilkan teks “Program setelah koneksi” tidak ditampilkan. Berbeda dengan Include.

Sampai sini sudah paham belum Pengertian dan Perbedaan Include, Require Pada PHP ? Sudah mengerti bukan ? karena insyaallah Contoh di atas sangat jelas dan mudah untuk di pahami. Yuk lanjut ke Require_Once dan Include_once


Require_Once / Include_Once 

Keterangan : 
- Pemberian _once pada include maupun require akan memastikan bahwa file yang dikaitkan hanya akan jalankan sekali saja, walaupun file disertakan beberapa kali.
- Sebaliknya tanpa akhiran _once penyertaan file yang sama beberapa kali mungkin akan menyebabkan error.

Contoh Program :
1. Saya akan membuat file php baru yang berisi fungsi bernama foo dan  diletakkan di dalam satu folder yang sama dengan file pemanggilnya
Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh
Contoh fungsi


2. setelah itu saya memanggil file tersebut dengan file lain
Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh
error
Hasilnya error karena file diminta 2 kali (tanpa menggunakan _once).

3. Kemudian apa jadinya jika pemanggilannya menggunakan require_once ?
Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh
contoh require setelah eksekusi
Tidak ada error yang muncul :)

Sudah mengerti bukan tentang Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP ? Saya berharap iya. Jika anda memiliki pertanyaan silahkan komen di bawah ini ya


tag :
Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh, Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh, Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh, Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh, Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh, Pengertian dan Perbedaan Include, Require dan Require Once Pada PHP Dengan Contoh