Parsing Forms with Multiple Submit Buttons in Node.js with Express 4

Here is a very simple, bare minimum example to demonstrate how Express 4 and body-parser module.
I’m using ejs as the rendering engine because it looks like html.

Setup

Continue reading Parsing Forms with Multiple Submit Buttons in Node.js with Express 4

Simple File Upload with Express.js and Formidable in Node.js

Here’s a very simple upload example with express 4+ and formidable. According to Express doc:

In Express 4, req.files is no longer available on the req object by default. To access uploaded files on the req.files object, use a multipart-handling middleware like busboy, multer, formidable, multiparty, connect-multiparty, or pez.

So here’s an example combining the two.

The code is going to save the files you upload in disk under the folder /uploads in the root directory of the project. Continue reading Simple File Upload with Express.js and Formidable in Node.js

Send HTTP Requests To a Server with Node.js

It’s actually incredibly easy to send http/https requests to servers with Node.js. Node contains a bunch of native function for that, making it very easy to send REST requests. I’m going to demonstrate with Node’s own http.request(options[, callback]) method.

http-between-servers

HTTP/HTTPS requests in a very brief glance

The four most common HTTP requests are GET, POST, PUT, DELETE. The type of request determines the type of operation the request sender would like the server to perform.

Continue reading Send HTTP Requests To a Server with Node.js

How To: Request an Access Token for Autodesk APIs with Node.js

In this post I’ll demonstrate how to set up a simple Node.js server that will return an access token for Autodesk’s Web Service APIs. Every time you run the app, you’ll get a response in your console that contains the token.

Authentication API

Authentication API(link goes to official documentation) takes a POST request that contains your client id and secret in the request body. It sends you an access token that would expire in 1799 seconds – that is 30 minutes, to perform operations with Autodesk’s Web Service APIs.

The request:

POST /authentication/v1/authenticate HTTP/1.1
Host: developer.api.autodesk.com
Content-Type: application/x-www-form-urlencoded
client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=client_credentials

The response body should look like this:

{
  "token_type": "Bearer",
  "expires_in": 1799,
  "access_token": "Ttj3qdRiNRGQsu975PPXF578hzmP"
}

Now that we understood what the API does, let’s get started! If you’d like to skip the tutorial, all the code is in a GitHub repo.

Continue reading How To: Request an Access Token for Autodesk APIs with Node.js