Minimal NodeJS App, #minimal_nodejs_app - MareMakom
Minimal NodeJS App

The following code will run a minimal node js app.

You may use it as a boilerplate for your project.

// Import required modules const http = require('http'); // Define port const PORT = 3000; // Create HTTP server const server = http.createServer((req, res) => { // Set response headers res.writeHead(200, {'Content-Type': 'text/plain'}); // Send response res.end('Hello, world!\n'); }); // Start server server.listen(PORT, () => { console.log('Server running at http://localhost:${PORT}/'); });

Save the above code 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:

node app.js

If you want to do the same using Express.JS, you should first install the express package using NPM

npm install express

Then you'll be able to create and run an app.js file as same as you did above:

// Import required modules const express = require('express'); // Create Express application const app = express(); // Define a route app.get('/', (req, res) => { res.send('Hello, world!'); }); // Define port const PORT = process.env.PORT || 3000; // Start server app.listen(PORT, () => { console.log('Server running on port ${PORT}'); });

List of search results for the term "Minimal NodeJS App" on MareMakom:

For additional information, you may search for the term "Minimal NodeJS App" in external resources:

Average rating for this entry:   4.4 out of 5 (total 17 votes)
Your rating:

Comments and suggestions:

1. Add a link to a sandbox that presents a preview of the app.

Send a comment (will be published after review):

Additional information:
Search for another phrase
What others contributed:
Recently edited entries