Posted on 2 Comments

Complete Linux Networking Tutorial

Get The Complete Linux Administration Course Bundle!
https://josephdelgadillo.com/product/linux-course-bundle/

Enroll in the courses directly on Udemy!

A Beginner’s Guide to Linux System Administration!
http://bit.ly/2gHV6dD

CentOS and Red Hat Linux to Certified System Administrator!
http://bit.ly/2h7ONwE

BASH Programming Course: Master the Linux Command Line!
http://bit.ly/2y4GyY8

The Complete Wireshark Course: Go From Beginner to Advanced!
http://bit.ly/2yLpqIy

In this video we’re not going to be doing anything, we’re not gonna be learning about networking specifically on Linux. We need to understand a few general concepts before we get to that. So, this video is going to be a sort of introduction to networking on Linux. An introduction to networking in general. So, right now you are on a computerized device watching this video which is on the Internet. And the way that’s happening is basically you’re connected to a router, or a modem router all-in-one device, and the router is connected to your internet service provider, and your internet service provider has devices that are connected to the bigger world of the internet. So, you send a request, if you open up a browser and type in google.com and then hit enter, your web browser sends that as a request. It’s basically saying okay this is the web page that this computer wants to look at right now. It sends that through your router, which sends it to your internet service provider, and your internet service provider has all these fancy computers that properly route certain requests to DNS servers, any requests actually. What a DNS server does is it says okay, you gave me this string of text, a domain name or URL, and I have a record here that shows this domain or string of texts is supposed to serve up the content at this IP address. And so how the internet works is it doesn’t understand Google.com or Facebook.com. The internet uses network addresses, right, and so think of it like each web server, each server out there has and address just like every house on your street has an address. So, if you were gonna send somebody down the street to Joe’s place, you would say okay well go to this address, then you would give them the address of Joe’s place and they would be able to find it. The same thing is happening on a DNS server. You give the DNS server a domain name that you want to look at, and then th the DNS server takes that and says okay well I know this domain name is supposed to route to this IP address. So, you request, you need to go over to the server to get that content, and so your request then gets translated to an IP address and other information, and it gets to the web server that it’s supposed to be at. And then the web server running Apache or anything really nginx, I’m sure there’s tons out there that I don’t know about, but the web server receives requests, it receives all of the information related to it. So, cookies you know session variable stuff like that as well as the exact item you want to look at it. So, if you go to website.com/something /something else, everything after the .com/ is called a URI and that indicates what piece of content on the server you want. So, think of the first part domain.com as what server you need to be communicating with, and then afterwards you know /about.php or something that’s gonna tell the server once it gets the request what page it needs to send you. And then it does it’s you know rendering process and it sends you that page in the exact same route that your request took to get there. So, it’s like when you send your friend down the street to Joe’s place to pick up a box of pizza. So, your friend walks down the street he turns left you know maybe turns right, he gets to Joe’s place, he walks in says hey I need to get a pizza, Joe gives him the pizza, then he walks same way back to your house, and before you know it a web page has loaded within your computer box. That’s how that happens. I hope you guys understood that. In the next video we’re actually gonna cover a few more concepts before we dive into you know really understanding to the point that we can use applications to do certain things. So, I hope you guys found that informative. If you didn’t, if there’s any point in this video that you felt lost, or confused, or even that I was just rambling, or even if you just want to tell me you know a few more web server applications aside from Apache, there is a comment section to the side of this video. You just leave a comment I will reply and get you whatever information you need, and hopefully this will make sense to you. So, in the last video we described how the internet works, what the internet is, is technically an interconnected collection of networks. So, all these little networks all over the world can now be connected to other networks in the world, and so we have the internet which is just that. So, to understand the network here we’re bringing it down from you know the top level stuff, down to a more localized thing. And so a local network is the type of network that you have set up in your house, where you connect to the router, the router then you know can interact with the internet for you, and then return the information to you computer. Now, I wanted to talk for a moment about IP addresses and the current issues that face them, while still using ipv4. So, let’s open up a document here. So, an IP address looks like this. This is an IP address of a server somewhere, probably, if you put this in your browser…actually let’s try. That was just a random one that I just wrote up, let’s see what happens. This is probably the address of somebody, somebody you know, somebody is connected to an internet service provider and they get one IP address for all their computers, and the reason why that happens is because these IP addresses can go from 1.1.1.1 all the way to 255. So, as you can imagine the range is pretty big but it’s not quite big enough for the human population, and so we’ve been running out of IP addresses for the last fifteen or twenty years. And, multiple solutions have been brought into the equation to try and solve this problem. One of them was called a NAT. What this is is a network address. Basically, you have one router you have one IP address. So, the IP address you have let’s say is this one up here at the top, this is your IP address that the internet service provider has given you. Without the use of a router you can plug one device into the modem and your computer will use this IP address in requests, so basically when you send a request to google.com to load a page or to load a search what happens is your IP address gets sent to Google as well so that Google can return this data to your device. But, what happens when you only have one IP address and seven computers, that’s when the NAT comes into play. So, this IP address now is the IP address of your modem or router, and it assigns NAT addresses to all the devices on your network. So, let’s say you just have two devices on the network. The first one, actually the IP address of your actual router is likely this. I’ve seen one instance where a network did not use this IP address as its routers IP address. The IP addresses that your router will assign to computers in your home all begin with 192. So, basically it would be something like that, right, that would be the IP address, actually hold up I got this wrong. This is the IP address of your router, this is the IP address of your first computer. So, it always begins with 192.168 Your second computer might be this, and your 3rd computer might be this. So, now you have three IP addresses, three devices on your network and your router here is keeping track of them. So, from this device I type google.com into the address bar, what happens is this IP address along with the request gets sent to my router, the router then sends the request off to the ISP and then over to the internet and stuff, with the IP address of the router which internally is this and externally this is our ISP IP address they gave us. So, what happens this gets sent to google.com, google.com sends the page back to this IP address connected to the router here, the router then takes that request and connects it with the device that requested it, and then it sends it back to that device. And so that’s how a router interfaces between a local network and the internet. So, in the olden days before the NAT address and routers really took off each one of these computers would have had a different IP address, so it would have looked something like this. So, that would have been 3 actual IP addresses when we found a way that you actually only need one IP address for our network, and so that’s what a router does and so these IP addresses are local and you’re gonna see these in terminal. Now, one other special IP address is 127.0.0.1 On every computer this means this computer. It’s basically a self identifying IP address. If I were to type this into my browser I would see my localhost, where if you put this in your browser you would see your localhost. The NAT IP address basically works the same way. So, if I were to go to 192.168.0.3 it would try to find a computer only on my network that has this address and then connect to it. So, that’s how a router works, in the next video we’re getting into the ifconfig. On Windows you have an ipconfig command, on Linux here you’ve got ifconfig and we’re gonna cover that in the next video, and a a few other commands as well. So, thank you guys so much for watching, and I’ll see you guys soon.

Posted on

How to Transfer Files Between 2 Computers Using SFTP

Click here to subscribe for more videos like this!

Hey guys, let’s go over some SFTP. So, first what is SSTP? Well first before we answer that question, let’s ask a similar but different question, what is FTP? FTP is an acronym for the term file transfer protocol and it uses the port 21, and basically what it does is it transfers files between two machines. So, SFTP, because in regular FTP everything is transferred in clear text, so if anybody is sniffing packets on your network like we learned in a previous video, they would be able to read all those packets, basically. So, we’re not going to use FTP, I actually recommend never use FTP. SFTP is just easier anyway, and so we’re just going to use SFTP. So, similarly to the “ssh” command, you’re gonna write “sftp” and then the connection string. So, in my case it’s exactly the same as before. Then it asks for my password for the remote host, so I’m gonna put that in here, and now I can list what’s on the remote host by typing “ls” but we also have a few different commands to list what’s on the local host. I’m actually gonna exit here. I’m going to make a directory called “sftp-demo” I’m going to change into sftp-demo, and I’m going to “touch” a file called “names.txt.” Now, I’m going to reconnect while in this directory, to my server. Now, if I run “ls” I get the remote directories current directory listing, if I type “lls” I get the local listing of the directory that I’m in on the local host. And so here we can actually, we can grab files and transfer them to and from both machines. So, if I wanted to put names.text on to the server in the current directory, what I would do is type “put names.txt” and it’s going to upload it to my remote host with the same name. So, that’s when you would use “put” if you want to push a file from from your local machine to the remote host. Similarly, use the command “get” to get files. So, I’m going to, I really don’t recall any of these files, I’m just gonna get the composer.json file. So, I’m going to type “get composer.json” and if I run “lls” on my local machine I can now see that I have that file there. So, if I exit and then run “ls” I’ve got that file there. So, that is how you would use SFTP to transfer files to and from machines, and also a few commands there that can help you see what files are available. So, thank you guys so much for watching, and I will see you guys again soon.

Posted on

Using SSH to Access the Command Line of a Remote Host

Click here to subscribe for more videos like this!

Hey guys, in this video it’s all about SSH. So, first what is SSH? It’s an abbreviation that stands for Secure Shell and it basically allows you to access the shell or the command line of a remote host that has an SSH server setup. So, in one of the previous videos I connected via SSH to my own server and so I’m gonna do that again, and I’m going to explain exactly what I’m doing as I’m doing it. So, the way to get connected to a remote host through command line is using the “ssh” command, and then the only argument it’s gonna take is the connection string. So, in this case it’s my username on my remote host at, and then the remote host. So, I can use this or any other domain name that points to that server or I could use the server’s IP address, and when I hit enter it’s gonna ask for my password on that machine, so I’m gonna put it in and you’re gonna see that the prompt is gonna change. I’ve actually got this machine named the exact same thing is I have my server name, so it’s nick@voltron here, and I’m on my local machine. So, if I were to go to “var/www/html” and then run the “ls” command, I’m gonna see that I’ve got a lot of directories here actually, and a lot of these are actually unused and old projects that I worked on. But, anyway, basically once you get connected all the commands are the exact same because it’s essentially just a remote Linux shell. So, I could return to my home directory, then list those files, and you’ll see that again I’ve got just a bunch of random files. So, that is how to connect to SSH, when you’re done just type exit the connection will be closed. So, that was a really short video just to recap how to get connected is type “ssh” your remote user name at the name of the remote host, and hit enter and its gonna ask for your password. So, thank you guys for watching this video. In the next video we are going to be going over some SFTP, which is a bit bigger.

Posted on

How to Scan External Host Names & IP Addresses using Nmap

Click here to subscribe for more videos like this!

So, now you don’t only have to scan devices on your local network, you can
also scan external IP addresses or host names. So, I’m going to scan my server here by typing “nmap pointybracket.net” and then the host name of my server. It’s gonna take a moment and I’ve got a lot of open ports just because I have so many different things running. I’ve got, there’s a lot of things that run on it and some things that I just setup that I’ve never really used and haven’t bothered to shut them down, and so what we get here is my host and we can see that I’ve got FTP, SSH, SMTP, we’ve got the standard domain in HTTP, pop3, there’s a bunch of stuff here and I’m not going to go into what all those are but we can see that these are everything that the server has. You can also set a file, so let me clear this. Let’s open up gedit. So, we’re going to create a file of of hosts that we want to regularly scan and this can save time when we scan them if you’ve got like you know a few hosts that you regularly check on. So, I’m going to put “pointybracket.net” “192.168.0.1” and “192.168.0.100” and I’m gonna save this as “networks.txt” So, what we can do there is we can type “nmap -iL -/networks.txt.” so it’s a lowercase “i” and a capital “L” and then the location of that file, so it was “networks.txt” in my home directory. This is going to scan each of the hosts that is in that networks file. It returns in the order that they were scanned in, so that’s pretty neat. I want to go over a few more things with you guys regarding this command it does get pretty big there’s so much so that you can do with this, and so I really urge you guys to go and explore this if networking is one of your interests, if you want to really you know follow that. One of the things I want to show you guys is how we can turn on OS inversion detection during the scan, and so what we’re going to do is type “nmap -A 192.168.0-100” and this is going to scan, oh I had a little typo in the IP address there so I had just fix that, so this should tell me the operating system versions that are running on the devices on my network, and you can also find this information about other hosts. Aside from this, just while this is running you can scan aa network and find out which servers and devices are up and running by using the flag “-sP” You can display the reason that a port is in a particular state by having the flag “–reason” You can choose to only show opened ports which appears to be the default functionality here, it doesn’t show the closed ports. You can actually also show all of the host interfaces for a machine by typing “–iflist” in the list of arguments for this command, and I mean again it’s really big so go ahead and look this up. If you wanna type in google.com “nmap commands” there’s a bunch of different ones that you guys should play around with, this was more of an introduction onto the most common or basic functionalities of this program. I’m going to cancel this here and I’m just going to restart. This will go a bit faster, I’m just going to target my own IP address here so we can get this done and you guys can see the example output that this is gonna do when adding the “-A” slag in here. So, here you can see a lot of information about this machine. Let’s go to the top here. We’ve got the port, the state, and the service, as well as the version of the service. So, I have Apache 2.4.12 installed and that’s also the same one here. If we go down we get more information about the host cell, so we have OS UNIX, we’ve got the computer name, the domain name if anything is configured, the fully qualified domain name, and just a lot more information. So, that is the nmap command and it would be useful if you’re trying to just scan your network, and one of the examples that comes off the top of my head that would be you know when I would use command is if I noticed that the internet’s you know running a bit slow. Let’s say I’ve got 10 people in my house and half of them may or may not be using the internet and I wanna see how many people are online, this is what I would do in that instance or if you you know if you want to check how many machines offer a certain service, or what the IP address is that you need to use to access a certain service on another machine, this would help you figure that out. So, thank you guys for watching this video, I will see you guys again soon.

Posted on

Nmap Install & how to get Started

Click here to subscribe for more videos like this!

Hey guys, welcome back. This is the last video in the networking module. I just want to give you guys the tools you need to further your knowledge of networking in general, and how networking tasks would be performed on Linux. So, there is one more tool that I want to introduce you guys to called “nmap” So, nmap is an abbreviation for the term network mapper, and it’s an open source tool that can tell you what devices are on the network, what IP addresses are in use, and what services each machine is offering. So, let’s go ahead we need to install the tools so let’s run “sudo apt-get install nmap” and it’s going to download about 3 megabytes of data and it’s going to expand to 18 megabytes. Alright, now that this is installed the way we’re going to use this is by simply typing and “nmap” and then we can do a bunch of things after this. So, the first thing we’re gonna cover is how to scan specific IP address, so I wanna get the IP address that I have so I’m gonna run “ifconfig” So, “nmap 192.168.0.100 and we can see what ports are open, well we can see what ports are available, their state, and then also the service that they provide by name. So, I have Apache installed on this machine, you guys should have it installed on yours as well, if you went through the Apache videos and so you should see the same
thing here. And so the port is 80, the state is opened because we’ve got we’ve got Apache running right now, it automatically runs when start up the machine, and the service that the port provides is http. So, if I were also running an SSH server on this machine you would see another entry in this list for port 22, it would say state open, and service SSH or something to that effect. Now, if we want more information we can run “nmap -v” then the IP address again, so “192.168.0.100” “-v” means verbose and what verbos mode does in most applications is it also, aside from the regular output, it also gives you more direction on what’s happening in the application or provides more information than you would normally get, so in this instance we see that it’s doing a bunch of scans. It scans the IP address then for 1,000 ports and it finds all these ports that are open, and then also finds a bunch of a bunch of closed ports listed here, closed ports, and it it gives us the same output as before. So, that’s neat, I only have one device on my network actually except for my router. Now, my router I believe is 192.168.0.1 So, that is the IP address for my router, so what we can do is scan multiple IP addresses at a time in multiple ways. So, the first way that we’re gonna do is by specifying each IP address. So, let’s go ahead and run “nmap 192.168.0.” and then we’re going to add the last values in here separated by comma. So, first I’m going to scan my machine as well as the router and if I had a network address of 192.168.0.10 I could also do that, but I don’t so I’m not going to. Now, what we see here would be my router. We can see this is the IP address for it and this is what services it offers on which ports, and then we get my machine right here that provides the same output as it does before but this is how it would output multiple machines scan results. Now, you can also scan a range of IP address. So, let’s go ahead and run nmap command again 192.168.0.1-100 this is gonna go from 1 all the way to a 100 and it’s gonna scan all IP addresses within that range, so if I had a bunch of machines on my network, which I actually do I have my phone on that network as well, and that’s it actually so I’ve my router, my computer, and my phone. My phone is not coming up so I’m not doing anything on my computer right at the moment, I’m just checking what IP address I have on my phone here, if I can find out how. Ok, so the IP address on my phone is .101, so I’m what gonna do is run the previous command and just have it scan from 1-101. We should see three machines come up, I don’t think my phone has any services or open ports that it would list, but let’s have a look here. And when you scan multiple IP addresses the more you ,the longer it takes. Okay, so there’s nothing available from my phone coming up. Now, you can also scan, so when we talked about IP addresses we discovered that you can use anything from 0 to 255. So, if I were to want to scan all IP addresses that begin with 192.168.0, I could then put this in here, right, but rather than doing that we can actually use a wild card here. And, I’m actually gonna cancel this because it’s gonna take a while.

Posted on

Using the Traceroute Command to Track Server Requests

Click here to subscribe for more videos like this!

Hey guys, we’re about to talk about the traceroute command and what it does why you use it, but first we need to install that program. So, just come along with me run “sudo apt-get install traceroute” and it will fetch that from the repositories and install it for us, and when it’s done we can run the command. So, run “traceroute” all one word and then the domain that you want to trace the route to, and it’s gonna spit out every server that the request jumps from and to in order to get to Google’s server. When you see “* * *” it means the request has times out on that server so it’s gonna try another one. There we go. Let me make this bigger so it might be easier to read here, alright. So, we can basically trace what servers we are communicating with in order to gets to google.com. So, when I when I type in google.com into my browser, it doesn’t just go from my router, the request doesn’t get sent automatically right to Google servers, what happens is there’s a lot of intermediary servers in between the two including your ISP, the DNS servers, and then other servers that need to be hopped to order to get to Google, So, this is what we’re seeing here. The first request, this is the IP address of my router, this is the length of time that it took to get there. What happens then is this address is where this goes and you can see each address as we go down gets a bit different because we’re going to a different part of the world. And the host name will show if it’s available too with the IP address in brackets, so we can see this my ISP and this is one of their servers that my request has to hop from in order to get the information required to get to google.com. So, I’m gonna try it with my own server here so I’m just gonna type “traceroute pointybracket.net” and we can see that is accessing different servers in order to get to where it needs to be. So, in here we can see two interesting things, first of all my internet service provider, and second of all my virtual private server provider, and I’m not going to point those out, but we can see that and then we can see also everything in between that holds information about the route that our request needs to take in order to get to that server. So, that’s how to use trace route and that’s why you would is just kind of to you know trace the route of your request to different servers. So, thank you guys for watching this video and I will see you guys again soon.

Posted on

Linux Host File Explained

Click here to subscribe for more videos like this!

Alright, so I just had to restart Firefox here. This is the default server page, the route page for my server, if were gonna “server.pointingbracket.net” and actually get the exact same page, and so what I can do I believe is access the routes on the server as normal and it works. So, what we’re doing as you can see is we’re just, we’re just setting DNS records internally for this machine that it looks at before it goes at you the correct DNS information. So, again I’m gonna go to network-tools. We’re going to try with like, let’s try and find Joe’s Pizza, a
website for them, there we go. So let’s see if this works. This is the IP address I’m getting. So, I’m going to check if that IP address will route to the website as well. No, but it routes to this page. This is the page we should see after we paste this in to our hosts file. Let’s go ahead and save, and then let’s go to “go/” Close this, and there we go. And you can see how this works is basically it routes to whatever we want to route to. So, you could create shortcuts for your favorite websites with the exception of Google, Google does a lot of internal routing and stuff. Sometimes this will work, sometimes it wont. It all depends on how the web server is setup. Usually though I just use the hosts file to set domains to go to my localhost, and that’s for when I’m developing something that a URL needs to be set with. So, if I’m developing a WordPress site on my local machine and I need to set up a URL in the WordPress configuration, I would configure a domain and then point it to my localhost. So, that is the hosts file. Let’s exit out of here, close this, clear that. So, now our hostname. A hostname is basically a name of a machine, and in this instance ours is called Voltron and we can see that because we’ve got this right here. So, you can use the hostname much like the same way you can use you know custom hosts that you set, so I can just go to Voltron and its gonna route to my Apache default page. Now, you can also update the hostname and we need to do a couple things in order to do that. So, first we’re gonna run the command “sudo hostnamectl set-hostname and whatever host we want to name it to. So, “Megazord” Now we need to edit the hosts file to update our host name here as well. So, we’re going to replace “Voltron” with “Megazord” and save this and close it, and we’re gonna run “sudo service hostname restart” It said it failed to restart the hostname service, but it looks like it’s working hostname is now set to Megazord, and if I were to close the browser and reopen it I should be able to go to Megazord/ and it does in fact redirect me to my default Apache 2 page. And so that’s what a host name is and how to change it on Ubuntu, you can also change it through the system settings but we’re not going to go through a GUI way to do this right now. So, thanks for watching I hope you guys found this informative. If you have any questions just leave a comment, otherwise I’ll see you guys soon.

Posted on

Putting the Finishing Touches on our Meteor Project

Click here to subscribe for more videos like this!

Alright guys, this is getting closer to done. We now have a new working way to insert posts and also, view the posts here. One thing you’ll notice is that we’ve got posts by two different people. So, how Meteor should handle this in React and Flow Router. We’re going to modify our home component a little bit to be able to use a different route, so I’m going to go on my router file here FlowRouter and let’s name the route posts-by and then user. So, the colon here basically means that while post is going to be the name of a variable, and we can use that variable by accessing params. So, what I’m going to do is name the route Posts and the action we’re going to pass Params to the action is going to be renderView I’m going to reuse the home component here, but I’m also going to pass it in with user property and that’s going to be equal to params.user and so now, I’m going to close this component and end that with semi colon. I actually need to that there It got a little displaced there. Silly issue. When we create new routes, we need to type Flow Router.route Alright. What we need to do now is we need to make this conditional if we’re on basically in the router, we’re passing a user property here, but we’re not here so we can use this to identify if we’re on this route. So, what we’re going to do here is when we get post method I’m going to say if this.props.user we’re going to return Posts.find where the user is equal to this.props.user we’re going to fetch those else, we’re just going to return all the posts. So, if I go back here, and refresh this, I’m going to see when I view posts by Nick, that these are the only results I get, and when I view posts by Pete, these are the only posts I get. And still accessing the home page I will get all of the posts. And you can see how you can really reuse components here to be able to serve conditional data. Now, that’s basically, all Meteor is. It’s very simple and straightforward. I use it with React and Flow Router, I really recommend it. It’s much faster, it’s basically quicker to do everything. It’s quicker to develop, It’s quicker to browse. It makes your app faster in general. I hope you guys found this tutorial informative. I know it’s a bit longer than the other ones. And so hopefully, you know, the next few videos will be shorter, I think they will. And I’m going to actually provide this code to you guys. through GitHub, so right now, we’re going to be combining a bit of what we’ve been doing. So, I’m going to GitHub.com I’m going to create a new repository here, and I’m going to call it Meteor React Tutorial. And let’s initialize it with a Readme file, and then all the usual stuff. So, right in the directory here git init, git remote, add origin, I need to paste that URL here. I’m going to close WebStorm, so that we can get rid of the .idea directory. So, we can just use the regular rm -rf .idea, there. And then we’re going to run git -ignore/* git add -A git commit -m the message is going to be Example meteor react stuff and git push origin master. Here we go, if I refresh this, we should see, here is the entire Meteor project that we just created. You can find it a GitHub.com/nickgermaine/meteor-react-tutorial Thanks for watching this video, I hope you guys found it informative, if a bit long, hopefully, the next set of videos should be a bit shorter.

Posted on

Rendering the Posts in our Meteor Project Using React

Click here to subscribe for more videos like this!

So, let’s create a component to render the post. So, in the home directory under components, I’m going to create a new file and I’m going to call it Post.jsx So, as usual, Post = React.createClass and up here. And what we’re going to do at this point is something a little different. Because each post that’s rendered needs to be rendered with this single post. So, what we’re going to do is we’re going to pass the post id as a property to this function. So, let’s just render, and let postid = and then the post id. This.props.postId Now, something I like to do if we’re passing multiple properties and they’re always passed in as these props and then the name of it. What you can do, you can actually, do this. So, wrap your variables in these curly brackets. And let’s say I also had a post image and whatnot and this will say basically, each one of this is equal to this.props. whatever it is. So, it’s really useful when you’re using multiple ones. And right now, I’m going to console log post.id and then the post id return div There. So, what we’re going to do is we need to map the posts, actually let’s get to that after let’s add a couple tasks in here, so we can actually pull them out and see what we’re working with. Username Nick This is my first post Save. And I should set it to automatically reset this to default empty when we save it. This is another post and then something you’ll really enjoy. So now, I’ve got three posts. And I want to pull them out them down here. So now, to render posts we need to create a couple of methods here in the home file. So, one of them is going to be called getPosts We’re going to pass it an id and the other one is going to be called renderPosts So, what we’re going to do is the get posts is going to return all of the posts because I didn’t need to pass it an id. So, get posts, let’s just return Posts.find fetch and then from here, from render posts, we need to return this.getPosts and then we’re going to map and we’re going to call it post here, and put a little fancy arrow, to an object, we can end that with a semicolon and we’re going to return the post component with the post being sent as an attribute or a property. Let’s end that with a semicolon as well. And what we need to do is in here, in the main body, I’m going to put a line break there, and then I’m going to call this renderPosts Let me have a quick look over here, make sure it’s all good. Looks all good. So let’s go back here and what we need to do, is in post. Ah, see there we go! In post, I’m just returning this, so let’s do class name is card and then in here, let’s go with an h3 tag and here, see this property that’s what I’m expecting to get and so the post is the only property I am setting over here. So, I’m going to in curly brackets here, I’m going to put post.user and then in a paragraph tag, I’m going to put post.content and Save. And so to recap, what we are doing is we are mapping the results of this function to basically this, and this is a new way we can actually pass each item from these results, over as posts to this little block here, which returns the component and we pass the posts through with the property name of posts, so in the post component we can reference the entire post as this from this props. So, we go back here and refresh I’ve got through there and this is not working. What have I done wrong? So, I’m going to pass the id along as a key property here. Posts._id and the reason why it wasn’t rendering the post, which is because I forgot to add the brackets here, so that it runs this function. So, if I save that, go back here and refresh, I’m going to see this. Now, I’m going to, let’s say Add a few of these here. And the great thing about React is when something changes, it scans the document, and you’ll see over here React ids and it performs a div of the current content vs the new content and only rewrites the portions that need to get rewritten. So, it’s a lot faster, that’s why it’s better to scale using React than Blaze. Second post of mine, which will be a bit longer. So, I’m going to style this up a bit, I’ll be right back.

Posted on

Getting in to the Programming of our Meteor Project

 

Click here to subscribe for more videos like this!

What we’re going to do next is get into the programming of this. So, I want to close this, because I no longer need them. And in server, I’m going to create a new directory called Collections. And in here, I’m going to create a new file and I’m going to call this collection, posts. And so, posts=new Mongo Collection posts. And then, I’m going to write Posts.allow insert: function return true: update: function return true: and remove: function. Function, return true. And this is going to allow us to insert update, remove from that collection. So the posts are going to let’s create a way to put the posts in first. So in the Home page, let’s actually I’m going to create a new component here called a InsertPost.jsx Insert Post is going to be the name. It’s going to be put to React.createClass And I’m going to basically render some html to put a post in to the database. So I’m going to form actually I don’t need that. Let’s just use a text area placeholder is going to be Type a post, name is going to be actually let’s just give it a className. And we’re going to put form-control and id of a post-body. The male tag has empty body, alright, and then a button. So, button className is going to be button, btn.info and it’s going to say, Save Post. Let’s save that in the home component, let’s render that. So let’s just InsertPost, there. Alright, I have to wrap it here. There, alright. Let’s indent this so it doesn’t look too bad. And if we refresh this, we’re going to see that our new component has been rendered. But if we type stuff, it doesn’t do anything right now. So let’s have an insert to that collection over here. And how we do that is we’re going to create a new function here called insertTo Collection it’s going to take event. So once you start getting more functions in React components, you need to separate them with comma. And what we’re going to do is we need to, say, onClick and in curly braces type this and then the function name. So this is going to be insert to collection. And we’re not passing anything to it so you could leave out the brackets here at the end. And the first thing we’re going to do is event.preventDefault And then we’re going to get the post body. So, content… Actually I need to var content= or we can just use straight up
Jquery here to get post body. I’m going to console.log content make sure we’re getting it. Didn’t mean to copy that, there. So let’s save that. Come back here, refresh this. There we go. And so we are getting that content into that function. So from this point, it’s a basically regular Meteor stuff, we’re going to type Post insert and then content just content. So, save that and refresh and actually to be able to I’m going to wrap this in a form element just because it’s so, that we can hit Enter, in the text area. And it will also submit it. So, onSubmit we’re going to call this .insertToCollection So, we can just actually change this to type =Submit and remove this part here and this button will also function as a means to insert it to the collection. So, to come back here and refresh let’s make sure that it gets into the collection,so This is a post to insert to the collection. I’m gonna hit Enter. Alright, this is a text area, nevermind. I’m gonna save that. And it logs it out, and If I want to make sure that it inserts it successfully, I’m going to in the console log here, I’m going to find and let’s just do that fetch, and it did put it into the database with content there as the key. So, let’s actually extend that a bit further by adding, date, added, it’s going to be new date. And if you want to be able to read it easier, you can do this, that’s what I usually do, and it’s going to make it easier if you get like huge objects that you are putting in to the collection. So, I’m going to delete that console log now. We do not need that. So, now, we’ve got this working, it’s a component to insert post. But how can we get them out of the database? So, over in our home component, I’m going to do a couple of things, First, it’s going to be, I’m going to add a property called mixins Put a colon and then, this. I’m going to type MeteorReact ReactMeteorData So, now we can create a new function and it’s going to connect MeteorData to the component and the function name is going to be getMeteorData We open it up, we do this. So, right now, I’m going to just get all the posts. And so, I’m going to variable posts, = posts, find fetch. And then in here, we’re going to return certain things to the render function. So, I’m going to just type return and then open up curly brackets here. I’m going to return posts as posts. We’re gonna save this. And now, what we can do is we can access that from the render function by for instance create a variable here called allPosts and is = to this.data.posts I’m going to console log all posts I’m going to save that I’m going to refresh this page, and it’s going to log all the posts, which right now, this is the only one we have. So, that’s awesome. How do we get it into here? Ah, well, let’s actually go back to insert posts here. I’m going to create an input field class name is going to be form-control The idea is going to be, user and the placeholder is just going to say, username. And that let’s put a line break there. I’m also going to put a line break down here. I’m going to also handle this: var user = just straight up JQuery from here, the idea of user .val I’m going to insert that to the collection as well. So, user = user and then a comma. So, we now have three fields that will get entered into the collection. I’m going to remove the current one we’ve got. Because, it doesn’t have this necessary information in it to render it. So, I’m just going to type posts find fetch, I’m going to get that ID, I’m going to say, posts.remove id that connector. Now, if I run post find fetch, it finds nothing because we’ve just removed them.