[NODEJS] Starting a Node.js Project with Express
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:
- Create a folder and name it whatever you want (project name).
- Right click on the folder and open in Git bash.
npm init
command will create apackage.json
file in the project folder which would contain all the information about the project, like: dependencies, author, etc.- The value for the key
main
that isindex.js
indicates that index.js would be used as an entry point for the project. - Now, output you throw in
index.js
file will be displayed in the command line withnode index
command. - In order to render output in a browser
express
framework is needed, which we can get usingnpm install --save express
. Here--save
is used to add express as a dependency in thepackage.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
!