Skip to content

Commit

Permalink
Update and rename Nodejs Express.html to Nodejs Express.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lwindolf authored Jan 5, 2024
1 parent 073637f commit 3bc4a33
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 47 deletions.
47 changes: 0 additions & 47 deletions examples/Javascript Examples/Nodejs Express.html

This file was deleted.

40 changes: 40 additions & 0 deletions examples/Javascript Examples/Nodejs Express.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Generate Express project

npm install express-generator -g

express <name> # Create boiler plate

## Enabling CORS in Express

To set CORS headers add an `app.use()` block like this

app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://server:8080');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});

## Debugging Express Applications

Ensure to install the 'debug' module

npm install debug

And the run with debugging enabled by setting the DEBUG environment variable like this

DEBUG=express:* node index.js
DEBUG=http,mail,express:* node index.js

DEBUG=<app name> node ./bin/www

DEBUG_FD=3 node index.js 3> logfile

Debugging code would look like

d = debug('http:instance1');

d('Some logged event');
d('Another logged event');

0 comments on commit 3bc4a33

Please sign in to comment.