An app that, on file upload, returns a JSON response which includes a 'name', 'size', 'date', and 'file'.
{
"name": "Screen Shot 2018-02-05 at 5.56.07 PM.png",
"size": 141907,
"file": "imgFile-1517888421866.png",
"date": "2018-02-06T03:40:21.899Z"
}
- I can submit a FormData object that includes a file upload.
- When I submit something, I will receive the file size in bytes within the JSON response.
- Express: Fast, unopinionated, minimalist web framework for node
- EJS: Embedded JavaScript templates
- express-ejs-layouts: Layout support for ejs in express
- express-session: Create express session middleware with given options
- express-flash: Rendering flash messages without redirecting the request
- body-parser: Node.js body parsing middleware
- cookie-parser: Parse Cookie header and populate req.cookies with an object keyed by the cookie names
- mongoose: MongoDB object modeling tool designed to work in an asynchronous environment.
- connect-mongo: MongoDB session store for Connect and Express
- multer: Node.js middleware for handling multipart/form-data, which is primarily used for uploading files
- dotenv: Load environment variables from .env file
Create your own server. I used mLab.com. Create a user on that server.
Create your own .env file in the root directory with a DB_URI which links to your server. Here is an example:
PORT=8000
HOST=127.0.0.1
DB_URI=mongodb://<dbuser>:<dbpassword>@ds125588.mlab.com:25588/answart-file-metadata-ms
DB_USER=<dbuser>
DB_USER_PASS=<dbpassword>
SECRET=my-super-secret
Install dependencies then launch app @ localhost:8000.
$ npm install
$ npm start
Command | Description |
---|---|
npm install | Install dependencies in package.json |
npm start | Start server @ localhost:8000 |