Giter VIP home page Giter VIP logo

node-express-app's Introduction

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

node-express-app's People

Contributors

profcase avatar denisecase avatar mprogers avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.