<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mariam Adeyemi</title>
    <description>The latest articles on DEV Community by Mariam Adeyemi (@mariamadeyemi).</description>
    <link>https://dev.to/mariamadeyemi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F987223%2F909efd19-b248-4c2c-8c32-34163cafcb4d.jpg</url>
      <title>DEV Community: Mariam Adeyemi</title>
      <link>https://dev.to/mariamadeyemi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mariamadeyemi"/>
    <language>en</language>
    <item>
      <title>Connect Your Node.js Project to MySQL Database Locally</title>
      <dc:creator>Mariam Adeyemi</dc:creator>
      <pubDate>Wed, 04 Jan 2023 10:39:17 +0000</pubDate>
      <link>https://dev.to/mariamadeyemi/connect-your-nodejs-project-to-mysql-database-locally-3opm</link>
      <guid>https://dev.to/mariamadeyemi/connect-your-nodejs-project-to-mysql-database-locally-3opm</guid>
      <description>&lt;p&gt;There is more than one way to connect MySQL database to node.js and in this tutorial, we are going use one of the easy ways to do it. With the use of XAMPP and mysql2 package, our connection will be set up in no time. No worries if you don't know these two, we are going to do this step by step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Xampp
&lt;/h2&gt;

&lt;p&gt;Xampp is a control panel or cross-platform server that enables developers to create and test their programs locally. Xampp is going to provide the GUI(Graphical User Interface) of our database. It will allow us to create databases and the data we need for our project.&lt;/p&gt;

&lt;p&gt;Visit the &lt;a href="https://www.apachefriends.org"&gt;apachefriends&lt;/a&gt; website to download the suitable xampp for your operating system. Follow all the necessary procedures and install it. After the successful installation, open the program:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RabKLjna--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnp2kfd9w4zwoypb1tyi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RabKLjna--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnp2kfd9w4zwoypb1tyi.png" alt="Xampp control panel" width="755" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Start the first two modules on the panel(Apache and MySQL).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XknwS2yK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2oawmvdcgoli62pbon3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XknwS2yK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2oawmvdcgoli62pbon3m.png" alt="Xampp control panel with apache and mysql started" width="679" height="545"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will start the SQL database locally which you can access on a localhost server. Open your browser and go to &lt;code&gt;localhost/phpmyadmin/&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wtIzG01H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ndereu19p8ngpf17uv0r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wtIzG01H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ndereu19p8ngpf17uv0r.png" alt="phpmyadmin tab" width="880" height="111"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a new database, click on the &lt;strong&gt;new&lt;/strong&gt; button at the side panel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NJ6Aq34H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9t9pdqq0h3z6bofeue4c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NJ6Aq34H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9t9pdqq0h3z6bofeue4c.png" alt="create database" width="880" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give your database a new name and click create. It should show up in the side panel after it has been successfully created. You can access it and go on to create your tables manually or import a SQL file with your data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set Up Connection
&lt;/h2&gt;

&lt;p&gt;For this, we will make use of the mysql2 package. Install mysql2 to your project with &lt;code&gt;npm install mysql2&lt;/code&gt;. You should read the &lt;a href="https://www.npmjs.com/package/mysql2?activeTab=readme"&gt;mysql2 documentation&lt;/a&gt; to learn more about how to work with the package.&lt;/p&gt;

&lt;p&gt;In your model folder, create a &lt;strong&gt;connection.js&lt;/strong&gt; file and copy the code to establish a connection to your database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mysql = require('mysql2');
const connection = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: '', //your password. You could leave it like this, for now
    database: 'database_name'
})

connection.connect((err)=&amp;gt;console.log(err || 'Database Connected'))

module.exports = connection.promise()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can go on to import the &lt;strong&gt;connection&lt;/strong&gt; function(please be aware that it is asynchronous) anywhere in your project you want to query your database. &lt;/p&gt;

&lt;p&gt;And that's it, our node.js project is connected to MySQL database in few steps. &lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>mysql</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React.js Roadmap for Beginners</title>
      <dc:creator>Mariam Adeyemi</dc:creator>
      <pubDate>Mon, 02 Jan 2023 20:34:45 +0000</pubDate>
      <link>https://dev.to/mariamadeyemi/reactjs-roadmap-for-beginners-6g9</link>
      <guid>https://dev.to/mariamadeyemi/reactjs-roadmap-for-beginners-6g9</guid>
      <description>&lt;p&gt;React.js is a JavaScript library useful for building fast and scalable user interfaces. It is one of the most popular JavaScript libraries and easy to get up and running with.&lt;/p&gt;

&lt;p&gt;Before you learn React, it is advisable to have a good grasp of JavaScript especially ES6, and the concept of Object Oriented Programming.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Roadmap
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F99n1q4mmw1g420fns1fx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F99n1q4mmw1g420fns1fx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Node
&lt;/h3&gt;

&lt;p&gt;The first step is to download and install node on your local system.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set up
&lt;/h3&gt;

&lt;p&gt;To get up and running with react, you need to get a copy of the react library. You could do this with &lt;code&gt;npx create-react-app&lt;/code&gt; or use alternatives like &lt;strong&gt;vite.js&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  JSX
&lt;/h3&gt;

&lt;p&gt;JSX is JavaScript HTML. It allows us to write HTML in JavaScript, making its syntax look similar to HTML. It is important to get familiar with this language to start working with the react library. &lt;/p&gt;

&lt;h3&gt;
  
  
  Components (functional and class)
&lt;/h3&gt;

&lt;p&gt;Everything in React is made up of components, which makes them important to this framework. This is one of the most important React fundamentals you should start with. React has built-in components but you can also create custom components to build your app user interface. Components could either be functional or class-based.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Props and State
&lt;/h3&gt;

&lt;p&gt;Props and state are other important concepts needed for your components. You can pass properties(props) to your components to render differently based on the values of the properties. &lt;/p&gt;

&lt;p&gt;State, on the other hand, is any data that components want to use to render themselves. The &lt;code&gt;setState()&lt;/code&gt; function is used to render your state.&lt;/p&gt;

&lt;p&gt;You should learn these two and also when to use them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conditional Rendering
&lt;/h3&gt;

&lt;p&gt;This is no different from conditional statements in JavaScript. If you can use &lt;strong&gt;if/else statements&lt;/strong&gt; and &lt;strong&gt;ternary operators&lt;/strong&gt;, you will have no problem with conditional rendering.&lt;/p&gt;

&lt;h3&gt;
  
  
  Component Lifecycle
&lt;/h3&gt;

&lt;p&gt;This is another crucial concept in React you should learn about.  React provides several lifecycle methods that are used to listen for changes in your component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Hooks(useState, useEffect)
&lt;/h3&gt;

&lt;p&gt;Hooks are required to keep state in your function components. Hooks are functions that start with "use" and allow you to use various React features like tools for managing state and component lifecycles. As a beginner, you should start by learning how to use the &lt;strong&gt;useState&lt;/strong&gt; and &lt;strong&gt;useEffect&lt;/strong&gt; hooks. &lt;/p&gt;

&lt;h3&gt;
  
  
  Events
&lt;/h3&gt;

&lt;p&gt;React event handling has some peculiar conventions, such as using camelCase for event names (onclick - onClick). You should also learn these.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lists and arrays
&lt;/h3&gt;

&lt;p&gt;With the power of JSX, you can create lists of elements by looping through an array. This is an interesting concept you should also know about. &lt;/p&gt;

&lt;h3&gt;
  
  
  Compositions vs Inheritance
&lt;/h3&gt;

&lt;p&gt;These are object-oriented programming concepts. Inheritance occurs when a child class inherits properties from its parent class while composition describes a class that can refer to one or more objects of another class as instances rather than inheriting properties from a base class. You can use either of the two in React.&lt;/p&gt;

&lt;p&gt;To conclude, these are the fundamentals of React to get you started with the library. It is advisable to learn and practice these concepts before moving to advanced ones. &lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Important Node.js Modules You Should Know</title>
      <dc:creator>Mariam Adeyemi</dc:creator>
      <pubDate>Wed, 21 Dec 2022 14:44:59 +0000</pubDate>
      <link>https://dev.to/mariamadeyemi/important-nodejs-modules-you-should-know-2knm</link>
      <guid>https://dev.to/mariamadeyemi/important-nodejs-modules-you-should-know-2knm</guid>
      <description>&lt;p&gt;Here are important node.js inbuilt modules that you can't avoid using whether as a beginner or experienced node.js developer. &lt;/p&gt;

&lt;h2&gt;
  
  
  Filesystem
&lt;/h2&gt;

&lt;p&gt;Node.js filesystem allows you to work with files on your computer. There are several ways you can handle these files. You could create, read, write, update, delete, and rename a file. To work with the filesystem, the first to do is require it:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const fs = require ("fs");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The filesystem can be synchronous or asynchronous. To work with an asynchronous filesystem, require &lt;code&gt;fs/promises&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create file
&lt;/h3&gt;

&lt;p&gt;There is more than one way to do this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fs.open()&lt;br&gt;
fs.writeFile()&lt;br&gt;
fs.appendFile()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Any of these methods will create a new file if it doesn't already exist and they take in the name of the file, the content, and a callback function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
fs.writeFile("data.txt", "Hello World", (err)=&amp;gt;{
if(err) throw err;
})


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;fs.open()&lt;/code&gt; is quite versatile as it takes a "flag" argument that indicates what you want to do with the file. &lt;strong&gt;"w"&lt;/strong&gt; flag means the file is open for writing, and &lt;strong&gt;"r"&lt;/strong&gt; means you want to read from the file. It works for creating a file because if the file indicated does not exist, it's going to be created.&lt;/p&gt;

&lt;h3&gt;
  
  
  Read a file
&lt;/h3&gt;

&lt;p&gt;The method &lt;code&gt;fs.readFile()&lt;/code&gt; or &lt;code&gt;fs.read()&lt;/code&gt; is used to read from a file. This method takes the name of the file and a callback function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const fs = require('fs');

function readFile(){
  await fs.readFile("data.txt", "utf-8" (err, data)=&amp;gt;{
    if (err) throw err;
     console.log(data);
})
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Delete
&lt;/h3&gt;

&lt;p&gt;To delete a file use the fs.unlink() method.&lt;br&gt;
&lt;code&gt;fs.unlink("data.txt")&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Rename
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;fs.rename()&lt;/code&gt;. It takes in the name of the file then the new name followed by a callback function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fs.rename("data.txt", "newData.txt", (err)=&amp;gt;{
  if (err) throw err;
  console.log('rename successful!')
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Path
&lt;/h2&gt;

&lt;p&gt;To work with files on your system, it is important to be able to know the path correctly. There are two types of file paths. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Absolute path&lt;br&gt;
Relative path&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An absolute path specifies the location of a file or directory from the root or (/) directory.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;C: \desktop\tuts\data.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Relative path defines the path as related to the present working directory.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;data.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Node.js has an inbuilt path module that makes it easier to work with file paths. To use it, the first thing is to require it&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const path = require("path")&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This gives you access to different path methods and the most common you will mostly use/come across are&lt;code&gt;path.resolve&lt;/code&gt; and &lt;code&gt;path.join&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;path.resolve()&lt;/code&gt; method resolves a sequence of paths or path segments into an absolute path. The given path fragments are processed from right to left. If no path segments are passed, path.resolve() will return the absolute path of the current working directory.&lt;/p&gt;
&lt;h3&gt;
  
  
  path.join
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;path.join()&lt;/code&gt; method joins all given path segments together and then normalizes the resulting path. &lt;/p&gt;
&lt;h3&gt;
  
  
  path.dirname
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;path.dirname()&lt;/code&gt;method returns the directory name of a path, this is especially useful for knowing the directory where a file is saved. &lt;/p&gt;
&lt;h3&gt;
  
  
  path.extname()
&lt;/h3&gt;

&lt;p&gt;This method returns the file extension from the path. It starts from the last period character (.) to the end of the given string/path. If there is no period, an empty string is returned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;path.extname('index.html');
// Returns: '.html'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Stream
&lt;/h2&gt;

&lt;p&gt;Stream is another inbuilt module in Node.js that is used for working with streaming data. It is great for saving time and memory. When the data to be written or read in a file is huge, it is better to use streams. An example is uploading/downloading/streaming videos. Streams are readable and writable. You can have access to the stream module by requiring it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const stream = require('node:stream');&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
The methods &lt;code&gt;fs.createReadStream()&lt;/code&gt;and &lt;code&gt;fs.createWriteStream()&lt;/code&gt; are used to stream data to be written or read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http.createServer(function(req, res)=&amp;gt;{
 const stream = fs.createReadStream("data.json");
 stream.pipe(res); //streams the data inside the json file
}).listen(5000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Events
&lt;/h2&gt;

&lt;p&gt;As a JavaScript developer, you should know about events triggering and have worked with this concept more than you can count. Events refer to every action that occurs on a computer. Objects in Node.js can fire events, like the readStream object fires events when opening and closing a file. &lt;/p&gt;

&lt;p&gt;You can work with events in Node.js too as it has a built-in events module. You first require it to start creating, firing, or listening for your events. Also, events are instances of EventEmitter object, so you must create an EventEmitter object too to have access to its properties and methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const events = require('events');
const eventEmitter = new events.EventEmitter();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;EventEmitter&lt;/strong&gt; object allows you to assign event handlers to your own events. We use the emit() method to fire an event. Here is an example of how to work with events:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let event = new events.eventEmitter();

event.on('event-name', function (data) {
  console.log('You just did something:', data);
});

event.emit('event-name');

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code initialized a new instance of the eventEmitter object. The "on" method is used to create an event while the "emit" method fires the event.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTTP
&lt;/h2&gt;

&lt;p&gt;Hyper Text Transfer Protocol (HTTP) is used to communicate between the web server and browser among other things. It is used for transmitting hypermedia documents like HTML. Node.js has an inbuilt http module that is meant to tap into the power of HTTP. Node.js HTTP module is essentially used to create servers. We require it like this:    &lt;/p&gt;

&lt;p&gt;&lt;code&gt;const http = require('http');&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
To create an HTTP server in node.js, we use the createServer() method. The syntax looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const http = require('http');

http.createServer((req, res)=&amp;gt;{
  res.end('Hello World'); 
}).listen(5000);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;createServer()&lt;/code&gt; method takes a function that handles the request and response between the server and the user. The listen() method indicates the port where the server can be accessed (5000). &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How To Set Up An Express Server in a Nodejs Project</title>
      <dc:creator>Mariam Adeyemi</dc:creator>
      <pubDate>Fri, 09 Dec 2022 16:14:57 +0000</pubDate>
      <link>https://dev.to/mariamadeyemi/how-to-set-up-an-express-server-in-a-nodejs-project-31k4</link>
      <guid>https://dev.to/mariamadeyemi/how-to-set-up-an-express-server-in-a-nodejs-project-31k4</guid>
      <description>&lt;p&gt;Node.js is an open-source server environment powered by JavaScript. It is an excellent choice for JavaScript developers and diehard JavaScript fans who do not want to switch to another language to program the backend of an application.&lt;/p&gt;

&lt;p&gt;Express is a lightweight and adaptable Node.js framework that offers a comprehensive set of features for developing web and mobile applications. It makes setting up a node server easier and faster.&lt;/p&gt;

&lt;p&gt;Setting up an express server is incredibly easy and straightforward. We are going to do it in a few steps and with even less code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step One: Install Node
&lt;/h2&gt;

&lt;p&gt;The first step in this project is to install Node.js. Don't forget that this is a node.js project so this is an important part of our project that cannot be skipped. Head to the &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;node website&lt;/a&gt; to download the latest version of node. You can skip this step if you have it already installed or run &lt;code&gt;npm -v&lt;/code&gt; in the terminal to check the version of the node you have on your operating system. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step Two: Install Express
&lt;/h2&gt;

&lt;p&gt;Now let's install express into our project. Create a new folder for your project then open the folder in VSCode or any code editor/IDE of your choice. Create a new js file, you can name it &lt;strong&gt;"server.js"&lt;/strong&gt;. Open the terminal and run the command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install express&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;This command will initialize npm and install the necessary packages and dependencies. After it has been successfully installed, you should have three new files. A node module folder and two JSON files. If you check the package.json file, you will see something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "dependencies": {
    "express": "^4.18.2",
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tracks the dependencies your project has access to. In the next step, we are going to add a new dependency and it will show in this file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recommended Step: Install Nodemon
&lt;/h2&gt;

&lt;p&gt;This step is optional but necessary for efficiency. Nodemon helps to restart the server every time you save any changes. It prevents the tiresome process of restarting it yourself every time. So, let's go back to our terminal to install nodemon. Run the command: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -g nodemon&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The -g tag means globally and it enables you to use nodemon in all your projects, not just the current one. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step Three: Require Express
&lt;/h2&gt;

&lt;p&gt;Let's go back to our server.js file to finish setting up our express server. The first thing to do is to require express:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");
const app = express();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code required the express package and assigned the express function to a constant named "app". The variable name can be anything but it is conventional to name it like that. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step Four: Set Up Port
&lt;/h2&gt;

&lt;p&gt;Next, we going to set up our port to run our server locally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const PORT = 3000;
app.listen(PORT, ()=&amp;gt;{
   console.log(`Server is running at http://localhost:${port}`)
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code saved the port to a variable and called the "listen" method from our express framework. The listen method takes a single argument and an optional callback function. We passed the port number as the argument and called a function that will log something to the console once the server is set up successfully. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step Five: Run It
&lt;/h2&gt;

&lt;p&gt;Run the command &lt;code&gt;nodemon server.js&lt;/code&gt; in the terminal and if there is no mistake in your code, you should see the console.log message and your server running at the implied port. Congratulations! you have successfully set up your express server in a few steps. &lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: Hello World
&lt;/h2&gt;

&lt;p&gt;If we visit our port address in the browser, the page is going to show up blank. It is because our newly set up server is not sending any response for the page to display. We can solve this by routing. Let's make a simple &lt;strong&gt;GET&lt;/strong&gt; request to the home route and send back a "Hello World" response. &lt;/p&gt;

&lt;p&gt;Warning! The position of the following code is very important, you should make sure it comes after our first two codes that initialized the express framework and before the port listening code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get("/", (req, res)=&amp;gt;{
   res.send("Hello World");
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code makes a GET request to the home route which is represented with &lt;strong&gt;"/"&lt;/strong&gt; and sends a string &lt;strong&gt;("Hello World")&lt;/strong&gt; as a response. The get method takes an argument and a callback function. The callback function has two parameters: the request and response. We will talk more about routing and other concepts in later posts. Stay tuned for more.&lt;/p&gt;

&lt;p&gt;Until next time. &lt;/p&gt;

</description>
      <category>neovim</category>
    </item>
  </channel>
</rss>
