[NODEJS] Starting a Node.js Project with Express

Mayank Shekhar
1 min readDec 10, 2017

--

A guide to get you started with a Node.js project on a Windows machine.

Prerequisites:

Node.js, GIT Bash, and MongoDB should be installed on your system.

Steps:

  1. Create a folder and name it whatever you want (project name).
  2. Right click on the folder and open in Git bash.
  3. npm init command will create a package.json file in the project folder which would contain all the information about the project, like: dependencies, author, etc.
  4. The value for the key main that is index.js indicates that index.js would be used as an entry point for the project.
  5. Now, output you throw in index.js file will be displayed in the command line with node index command.
  6. In order to render output in a browser express framework is needed, which we can get using npm install --save express. Here --save is used to add express as a dependency in the package.json file. It is helpful when you migrate your project from your local machine onto a different server.

Hello World

//contents of index.js fileconst express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))app.listen(3000, () => console.log('Example app listening on port 3000!'))

Now run command node index and open localhost:3000!

--

--

Mayank Shekhar
Mayank Shekhar

Written by Mayank Shekhar

Sharing my experiences (programming and life).

No responses yet