The following code will run a minimal node js app. You may use it as a boilerplate for your project.
A minimal Node.js application can be created using the runtime's native http module without installing any external packages or dependencies. By calling http.createServer(), the script listens for incoming requests on a specified network port and sends back an HTTP response with headers and a body payload.
For production applications requiring complex routing, middleware, and template rendering, developers frequently adopt lightweight web frameworks such as Express.js. Below are standard code snippets for bootstrapping both a zero-dependency native HTTP server and a basic Express server.
Copy the following code to your IDE:
Save it to a file, and call it app.js.
Then you'll be able to run it from your command line (assuming that you have NodeJS installed in your computer:
If you want to do the same using Express.JS, you should first install the express package using NPM:
Then create and run an index.js file, similarly that what you did above:
And your server is ready to go!
Main Site for Minimal Node.js App
External websites and official resources for Minimal Node.js App:
-
Introduction to Node.js | Node.js Learn
Official Node.js getting started documentation explaining runtime fundamentals and architectural concepts. -
Node.js server without a framework - Learn web development | MDN
MDN Web Docs tutorial covering how to create a basic web server in pure Node.js without third-party frameworks. -
Hello world example · Express.js
Official Express.js starter guide illustrating a minimal Hello World server with basic route handling. -
How To Create a Web Server in Node.js with the HTTP Module | DigitalOcean
Step-by-step developer tutorial on setting up a web server and handling HTTP requests and responses using Node's standard library. -
Node.js HTTP Module
Reference documentation and live examples demonstrating HTTP module usage, request listeners, and response headers. -
Node.js - Wikipedia
Encyclopedic overview of the Node.js open-source, cross-platform JavaScript runtime environment and its history.
For additional information, you may search for the term "Minimal NodeJS App" in external resources:
- • Google (search engine): Google.com/minimal_nodejs_app
- • Bing (search engine): Bing.com/minimal_nodejs_app
- • Wikipedia (encyclopdia): En.Wikipedia.org/minimal_nodejs_app
Search for another phrase
Recently edited entries
1. When building an API endpoint, remember to set the Content-Type header to application/json and serialize the payload with JSON.stringify().
2. For deployment on cloud platforms like Heroku or AWS, always bind the listening port to process.env.PORT rather than hardcoding port 3000.
3. In modern Node.js versions (v18.11.0 and later), you can use the built-in --watch flag (node --watch app.js) for automatic restarts during development.