Skip to content

denisecase/node-express-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-express-app

A super simple web app with Node.js and the Express web framework

Links

Requirements

  • A browser (e.g., Chrome)
  • A text editor (e.g., VS Code, or Notepad++, or Chrome)

Benefits

  • Node.js non-blocking event loop supports many concurrent requests
  • Express framework for web apps offers concise, easy-to-use API
  • Built-in objects for application, request, response, with HTTP verb methods

Prerequisites

  1. Node.js installed
  2. npm Node Package Manager (comes with Node.js)

Keep Some Files out of the Repo

We added a .gitignore file to list files and folders we don't want to commit to the repo (e.g., the very large node_modules folder and our personal settings for VS Code).

Make Use of Free Packages

In addition to Node.js, we use additional free software packages. These are listed in package.json:

Development dependencies are listed separately in package.json as these aren't needed in production (e.g. when hosting your live app with a cloud provider).

Keep Dependencies Current

We use the "latest" version to keep current. In production, you'll choose a version to avoid breaking changes. Specific version numbers for all packages are kept in the auto-generated package-lock.json file.

Install Dependencies Locally

It's easy to install the dependencies so you can run and test your app locally. Open PowerShell here as Administrator, and run: npm install. Explore the new node_modules folder.

npm install

Start App

"Open PowerShell Here as Admin" and start your app with the node command.

node app.js

Open a Browser Client

Open a web browser. Try these URLs:

  1. http://127.0.0.1:3002/ or http://localhost:3002/.
  2. http://localhost:3002/hello
  3. http://localhost:3002/big
  4. http://localhost:3002/greeting/42
  5. http://localhost:3002/yo/Lohita
  6. http://localhost:3002/yo/Rahul
  7. http://localhost:3002/yo/Teja
  8. http://localhost:3002/fortune

Modify and Restart Your Node Server

After updating code, use hit CTRL-C CTRL-C to stop your Node server. Restart the server to see your changes.

OR Use Nodemon

See package.json "scripts" and explore the "run dev" entry. This script starts the server with nodemon ("node monitor") instead of node. Nodemon listens for code changes and restarts automatically. Run a script by calling it with npm:

npm run dev

Find Your IP address

Open PowerShell as Admin, run ipconfig. Locate your IPv4 address. Invite others on your network to interact with your server-side app.

ipconfig

Troubleshooting

If you get:

Error: listen EADDRINUSE: address already in use 127.0.0.1:3002

There is already an app running on the port. Hit CTRL+ALT+DELETE to see the tasks, and find the running app and Right-click / End Task to kill the current version. Then restart the app.

Terms

  • Node.js platform
  • Express web framework API
  • npm (Node package manager)
  • npx (npm package runner; npm + execute)
  • nodemon
  • npm install {packagename}
  • npm install -g {packagename}
  • npm start
  • package.json
  • .gitignore
  • localhost (127.0.0.1)
  • host
  • port
  • URI
  • URL
  • route
  • web server
  • web service
  • web client
  • web request
  • web response
  • web security & Helmet

Optional: Create an Express app from scratch

  1. Create a folder for the app (use lower-case-kebob-case).
  2. Add app.js, README.md, and .gitignore.
  3. Open PowerShell and run npm init to generate package.json.
npm install
node app.js

Optional: Creating files

In PowerShell, use New-Item:

ni .gitignore

OR in Bash, use touch:

touch .gitignore

Optional: Deployment

Heroku will host a server-side app for free. Install the Heroku command line interface (CLI). On Windows, use Git Bash to execute the commands - NOT PowerShell. Add an alias for 'heroku' in addition to 'origin'.

See Also

About

A super simple web app with Node.js and the Express web framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •