Intro to Phoenix: Starting your Project

Phoenix Elixir
Transcript

English (Auto-generated)

that was install the dependencies, if you recall, we could install dependencies using mixed steps, Target, which installs all the dependencies. One thing I may have forgotten to mention is that notice that there are a lot more libraries that seem to be installed here than the ones that are mentioned in um the actual decks function right here. And that is simply because some of these dependencies have dependencies on their own. So uh the next task here will not only install your dependencies, it will also install the dependencies of any library that you depend on as well. Yeah. Alright, so now that we have installed all the dependencies, it's actually attempt to run the project and that's done by running mix phx dot server. So I'm getting an error here, so I'll get to actually help you um fix that error in a bit. But for now um let me actually just take a note of this here, we can start our project by running mix phx whatsoever. Remember that Mix actually is a tool, it's actually with elixir, not with phoenix that help us manage our projects, help us run tasks and help us um create the project to start with and do many other things. So phoenix come built in with a number of tasks that are very specific to phoenix projects and they all start with phx a shortcut for phoenix dot and then something in this case like phoenix dot server. So in this particular case here, this complained that it says failed to connect postgres error now in many cases in this series, I'll intentionally either show the error or work through it because I actually want you to get comfortable reading the error messages that we get from phoenix and actually working on resolving these. So in this particular case I'm getting this postgres error, I mean it's his fatal 2800, you could go research with this. 2800 is um but there's a clue here that actually may help us. Maybe tragedy bucket ourselves. It says the role, Post Grass does not exist and Postgres a role is really just think of it like the user or like the way for us, like the user name to access to connect to the database. So in this particular case, um we need to connect to our database and um the way we do it here is there is this config folder and there's a number of e X s. Files. Remember X s are electric scripts, they don't get compiled, they get executed. Um and there's one, there's this conflict that the excess which is a configuration for the entire project, but there are also specific um configuration files depending on your environment. So there is one for development, one for tests and one for production, as you might have guessed we're in the development. So by default you start your projects in development mode. So the file that's in concern right here is this one dev dot e X s. So in this particular case um actually notice here right at the very top. Not surprisingly because it's, you know, a key element in our application, it says configure your database and it's assuming a default thing to a user named Postgres and a password. Postgres, it's connecting to local host which is the default. So this wouldn't change. So unless you're developing on a remote database, which is less likely this local host should be fine. The database name again, it should be okay as well. But what we want to change here is the user name and password. Now I'm using a Mac by default. The way I set up my Postgres database, I won't go into the details in here. But um alright, some notes here, make sure you change your fake slash death that he access to match your data. Postgres it would be configuration. Unfortunately, this varies a lot depending on the system you're using. Like the way you install Postgres on Windows is very different than the way you install it on and other flavors of Linux and such things like that. That's why unfortunately I won't be able to give an exhaustive list of all of them right here. But what I would do here, if you get stuck is to research, you know how to create a database and how to create a user name and password for for your database. In my particular case, in most Linux systems, if you've installed it using homebrew by the way to stop the server actually before backtrack here, I'll put you to stop the server. You can hit control plus see even on a Mac it's control control key and not the command key. Sometimes things that are controlled on a windows or Linux based systems are actually command on mac systems that said for this particular one, you actually have to do control C to stop your server. So I stopped my server right here. Um and I'm back to this depth notes here folder that includes the files for my for my older so um in my particular case five type, who am I? I'll get the user name for my uh system in this particular case, it's my full name to mom. Uh and by default if you've installed I I use homebrew, which usually goes like brew installed. Postgres. SQL So if you're on a Mac, I would recommend using this approach when you're installing your postgres, there are many other ways to install your postgres as well. But if you have used this approach, likely the default password will just be empty. So I can just um empty the password right here. For for for my case on Linux systems, I believe you did, you do have to set up a password. So you do have to log in to postgres and create a user name and passwords. You'd have to go through that step before you can run your project now. In this particular case, I'll show you another task here to create your database. You can run, there's another mixed grass for us which is mixed ecto dot Acto is the library we use to interact with our database. Okay, so I'll do here mix ecto dot create and that's basically it says generated. Dev Notes app created database. Um, dev notes that repo has been created. I'm gonna explain what this diagnosis that repo is. This repo is another library that we use through ecto to interact with repo with the database repo. So, um, but for now it created the database for us. Let's go now and try to run the server again. Mix phoenix dot server. So that error is gone. And now it's telling us access running Death notes with cowboy cowboy. Is the servers actually elixir based server, interestingly enough, that's one nice thing about elixir by the way, it's kind of a side note here is that it comes in with so many tools that in at some level you could actually use elixir for the whole stack, uh, including the web server itself and many other languages. Um sometimes you have to use engine X, which is a, like a sea based um, server to run your application, but in elixir you actually have elixir options, which is really nice. Even as we will see later for things like storing stuff in memory and having like a kind of a simple key value, memory storage. Sometimes you would use a realist for it. It actually exists in elixir. That's a really nice thing about the Alexa ecosystem in that way. So in any case here, so it's running cowboy, our server 127.0 dot 0.1. Which is the same as local host. So we have this endpoint right here so I'll copy this right here and then I will go and put this in your browser and voila here we have our phoenix application running, it says welcome to phoenix. Peace of mind from prototype to production. Mhm If you search for this particular phrase like let's say I pick here or like let's let's just search for welcome to phoenix, you will notice that it actually um exist right here. As a, as a test, I will show you later where this um pages coming from and how we could actually alter this page to um suit our needs. Of course we don't want this to be the homepage of our applications, We want to actually start to build our app. Thank you for tuning in and I will see you in the next lesson
160 Views 0 Likes 0 Comments

We go over how to launch your local server to run your project on localhost during development!

Comment
Leave a comment (supports markdown format)