DEV Community

Paul Ikenna
Paul Ikenna

Posted on

30 Days - Node & Express Challenge (Day 2)

Image description

Setting up my development environment: Installing Node.js and Express.

Day of two of this task (30 day challenge) is to Set up my development environment to work with Node.js and Express, and from all indication, its straightforward.

Here is how to set it up:

1) Install Node.js:
Node.js is a prerequisite for using Express.js. first i have to download and install Node.js from the official website, this i didnt do, because i already have node.js installed in my laptop.

But If you dont have it, just download and follow the installation instructions provided for your operating system.

2) Verify Node.js Installation:
When i installed node, i had to verify that it's properly installed by opening a terminal (or command prompt) and run some commands which will bring out installed version of Node.js. i believe is still the same process.

node -v

3) Create a New Project Directory:
Create a new directory for my Express.js project is what i did. You can do same using the mkdir command in the terminal.

mkdir my-express-app
cd my-express-app

4)Initialize a New Node.js Project:
Inside my project directory, i initialized a new Node.js project using npm. This creates a package.json file which will track my project's dependencies.
npm init -y

5) Installing Express
Now, I can install Express as a dependency for my project using npm.
npm install express

6) Creating my first Express App
I Created a new file, app.js, where i wrote my Express application code.

`const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
res.send('Hello World!');
});

app.listen(port, () => {
console.log(Example app listening at http://localhost:${port});
});`

7) Run the Express App
Finally, i ran my Express app by executing the app.js file using Node.js

After eveerything, I opened my web browser and navigate to http://localhost:3000. There i saw the message "Hello World!" displayed, indicating that my Express app is running successfully.

Top comments (0)