A super simple web app with Node.js and the Express web framework
- A browser (e.g., Chrome)
- A text editor (e.g., VS Code, or Notepad++, or Chrome)
- 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
- Node.js installed
- npm Node Package Manager (comes with Node.js)
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).
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).
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.
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"Open PowerShell Here as Admin" and start your app with the node command.
node app.jsOpen a web browser. Try these URLs:
- http://127.0.0.1:3002/ or http://localhost:3002/.
- http://localhost:3002/hello
- http://localhost:3002/big
- http://localhost:3002/greeting/42
- http://localhost:3002/yo/Lohita
- http://localhost:3002/yo/Rahul
- http://localhost:3002/yo/Teja
- http://localhost:3002/fortune
After updating code, use hit CTRL-C CTRL-C to stop your Node server. Restart the server to see your changes.
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 devOpen PowerShell as Admin, run ipconfig. Locate your IPv4 address. Invite others on your network to interact with your server-side app.
ipconfigIf 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.
- 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
- Create a folder for the app (use lower-case-kebob-case).
- Add app.js, README.md, and .gitignore.
- Open PowerShell and run
npm initto generate package.json.
npm install
node app.jsIn PowerShell, use New-Item:
ni .gitignoreOR in Bash, use touch:
touch .gitignoreHeroku 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'.