A Super-Quick Guide to Getting Started with Node.js & Express.js

Paige Miles
2 min readFeb 19, 2021

--

Download & install node.jshttps://nodejs.org/en/download/

Make your project directory. In your project directory add an index.js file

mkdir my-node-app
cd my-node-app
touch index.js

Initialize your node app.

npm init -y

Note: -y tag accepts the default criteria. Without it, you will be asked to make edits and accept criteria prior to initialization. Either way, the accepted information can be found in the package.json file and can be edited at any time.

Install Express.js

npm install express

Confirm express was installed by looking for it in the package.json file under dependencies.

touch .gitignore

To create a .gitignore file. Add node_modules to your .gitignore file. This prevents node modules from being pushed to Github.

Express Setup

In the index.js file:

Import express

const express = require('express');

Instantiate express application

const app = express()

Declare your port number

const port = 4000

Declare your first route/API endpoint

app.get('/', (request, response) => {
response.send('Hello World!')
})

Start the server

app.listen(port, () => {
console.log("listening on port 4000")
})

So, this is what your index.js file should look like now:

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response