Full Code of bradtraversy/nodeuploads for AI

master 6733fc81f487 cached
5 files
3.5 KB
1.1k tokens
1 symbols
1 requests
Download .txt
Repository: bradtraversy/nodeuploads
Branch: master
Commit: 6733fc81f487
Files: 5
Total size: 3.5 KB

Directory structure:
gitextract_n1g40klz/

├── .gitignore
├── README.md
├── app.js
├── package.json
└── views/
    └── index.ejs

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
node_modules


================================================
FILE: README.md
================================================
# NodeUploads

An example of how to upload images locally with Node.js and Multer.

### Version
1.0.0

## Usage

### Installation

Install the dependencies

```sh
$ npm install
```

### Serve
To serve in the browser

```sh
$ npm start
```

## App Info

### Author

Brad Traversy
[Traversy Media](http://www.traversymedia.com)

### Version

1.0.0

### License

This project is licensed under the MIT License

================================================
FILE: app.js
================================================
const express = require('express');
const multer = require('multer');
const ejs = require('ejs');
const path = require('path');

// Set The Storage Engine
const storage = multer.diskStorage({
  destination: './public/uploads/',
  filename: function(req, file, cb){
    cb(null,file.fieldname + '-' + Date.now() + path.extname(file.originalname));
  }
});

// Init Upload
const upload = multer({
  storage: storage,
  limits:{fileSize: 1000000},
  fileFilter: function(req, file, cb){
    checkFileType(file, cb);
  }
}).single('myImage');

// Check File Type
function checkFileType(file, cb){
  // Allowed ext
  const filetypes = /jpeg|jpg|png|gif/;
  // Check ext
  const extname = filetypes.test(path.extname(file.originalname).toLowerCase());
  // Check mime
  const mimetype = filetypes.test(file.mimetype);

  if(mimetype && extname){
    return cb(null,true);
  } else {
    cb('Error: Images Only!');
  }
}

// Init app
const app = express();

// EJS
app.set('view engine', 'ejs');

// Public Folder
app.use(express.static('./public'));

app.get('/', (req, res) => res.render('index'));

app.post('/upload', (req, res) => {
  upload(req, res, (err) => {
    if(err){
      res.render('index', {
        msg: err
      });
    } else {
      if(req.file == undefined){
        res.render('index', {
          msg: 'Error: No File Selected!'
        });
      } else {
        res.render('index', {
          msg: 'File Uploaded!',
          file: `uploads/${req.file.filename}`
        });
      }
    }
  });
});

const port = 3000;

app.listen(port, () => console.log(`Server started on port ${port}`));

================================================
FILE: package.json
================================================
{
  "name": "nodeuploads",
  "version": "1.0.0",
  "description": "Example for image uploading in Node",
  "main": "app.js",
  "scripts": {
    "start": "node app.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ejs": "^2.5.7",
    "express": "^4.16.2",
    "multer": "^1.3.0"
  }
}


================================================
FILE: views/index.ejs
================================================
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
  
  <title>Node File Uploads</title>
</head>
<body>
  <div class="container">
    <h1>File Upload</h1>
    <%= typeof msg != 'undefined' ? msg : '' %>
    <form action="/upload" method="POST" enctype="multipart/form-data">
      <div class="file-field input-field">
        <div class="btn grey">
          <span>File</span>
          <input name="myImage" type="file">
        </div>
        <div class="file-path-wrapper">
          <input class="file-path validate" type="text">
        </div>
      </div>
      <button type="submit" class="btn">Submit</button>
    </form>
    <br>
    <img src="<%= typeof file != 'undefined' ? file : '' %>" class="responsive-img">
  </div>

  <script
  src="https://code.jquery.com/jquery-3.2.1.min.js"
  integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>  
</body>
</html>
Download .txt
gitextract_n1g40klz/

├── .gitignore
├── README.md
├── app.js
├── package.json
└── views/
    └── index.ejs
Download .txt
SYMBOL INDEX (1 symbols across 1 files)

FILE: app.js
  function checkFileType (line 24) | function checkFileType(file, cb){
Condensed preview — 5 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (4K chars).
[
  {
    "path": ".gitignore",
    "chars": 13,
    "preview": "node_modules\n"
  },
  {
    "path": "README.md",
    "chars": 406,
    "preview": "# NodeUploads\n\nAn example of how to upload images locally with Node.js and Multer.\n\n### Version\n1.0.0\n\n## Usage\n\n### Ins"
  },
  {
    "path": "app.js",
    "chars": 1611,
    "preview": "const express = require('express');\nconst multer = require('multer');\nconst ejs = require('ejs');\nconst path = require('"
  },
  {
    "path": "package.json",
    "chars": 304,
    "preview": "{\n  \"name\": \"nodeuploads\",\n  \"version\": \"1.0.0\",\n  \"description\": \"Example for image uploading in Node\",\n  \"main\": \"app."
  },
  {
    "path": "views/index.ejs",
    "chars": 1281,
    "preview": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, in"
  }
]

About this extraction

This page contains the full source code of the bradtraversy/nodeuploads GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 5 files (3.5 KB), approximately 1.1k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!