Skip to content

Instantly share code, notes, and snippets.

@munkacsitomi
Created February 29, 2020 17:59
Show Gist options
  • Save munkacsitomi/feeabe8f652753b674a7c6072e7f5a8e to your computer and use it in GitHub Desktop.
Save munkacsitomi/feeabe8f652753b674a7c6072e7f5a8e to your computer and use it in GitHub Desktop.
A Node.js application using Express.js
const port = 3000;
const express = require('express');
const app = express();
const getJSONString = (obj) => JSON.stringify(obj, null, 2);
app
.get('/', (req, res) => {
console.log(`Method: ${getJSONString(req.method)}`);
console.log(`URL: ${getJSONString(req.url)}`);
console.log(`Headers: ${getJSONString(req.headers)}`);
res.send('Hello, Express.js!');
})
.listen(port, () => {
console.log(`The Express.js server has started and is listening on port number: ${port}`);
});
{
"name": "express-project",
"version": "1.0.0",
"description": "A Node.js application using Express.js",
"main": "main.js",
"scripts": {
"start": "node main.js"
},
"author": "Tamas Munkacsi",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment