Node.js as a web server
document objects used in front-end JS development (Node.js provides
- access files on your machine
- listen to network traffic on your machine
- listen to incoming HTTP requests that your machine receives, and send back responses
- access databases directly
Node.js is built on a single-threaded, non-blocking event loop, the V8 JS engine, and a low-level I/O API. It’s become super popular for building fast HTTP servers (aka web servers) with the Express web framework, ideal for high-traffic, data-intensive (but low CPU) applications. Like chat apps.
Node.js for local utilities
In addition, Node.js can provide a better local development experience. Node.js comes with npm, or Node Package Manager, where you can download and manage packages from a huge ecosystem of third party libraries. When you run
npm install <npm-package-name>, Node.js downloads the package, adds it to the
node_modules folder in your project, and adds the library as a dependency in your project’s
When you’re just creating a client-side application, Node.js and npm are solely to provide a better developer tooling. Once your code is compiled and built (using npm scripts), the code is no longer reliant on Node.js to run. It can be hosted as a static relying on any back-end language.
If you’re building your client-side application with React and use
create-react-app, npm scripts are set up out-of-the-box with
npm startuses Webpack to launch a hot-reloading dev server available at
npm testlaunches the
npm run builduses Webpack to create a production-ready version of the app, output in the
npm run ejectremoves the single build dependency from your project and allows you to customize configuration for Babel, Webpack, ESLint, etc.