├── .gitignore ├── .gitpod.yml ├── README.md ├── package.json ├── public └── style.css ├── views └── index.html └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | .env 3 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: gitpod/workspace-node-lts 2 | 3 | ports: 4 | - port: 3000 5 | onOpen: open-preview 6 | visibility: public 7 | 8 | tasks: 9 | - init: npm install 10 | command: npm run start 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Managing Packages With npm 2 | 3 | This is the boilerplate code for the Managing Packages With npm Challenges. Instructions for working on these challenges start at https://www.freecodecamp.org/learn/back-end-development-and-apis/managing-packages-with-npm/ 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fcc-learn-npm-package-json", 3 | "dependencies": { 4 | "express": "^4.14.0" 5 | }, 6 | "main": "server.js", 7 | "scripts": { 8 | "start": "node server.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/freeCodeCamp/boilerplate-npm.git" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /public/style.css: -------------------------------------------------------------------------------- 1 | /****** Main Styling ******/ 2 | 3 | body { 4 | font-family: 'Roboto', sans-serif; 5 | font-size: 16px; 6 | color: #222; 7 | background-color: #ECF0F1; 8 | text-align: center; 9 | } 10 | 11 | .container { 12 | padding: 0; 13 | margin-top: 40px; 14 | } 15 | 16 | .footer { 17 | margin-top: 60px; 18 | } 19 | 20 | ol { 21 | list-style-position: inside; 22 | } 23 | ul { 24 | list-style-type: none; 25 | } 26 | 27 | a { 28 | color: #2574A9; 29 | } 30 | /****** Logo Div Styling ******/ 31 | 32 | img { 33 | margin: 20px auto 0 auto; 34 | display: block; 35 | } -------------------------------------------------------------------------------- /views/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Backend Challenges | Free Code Camp 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 |

Manage Node.js projects and npm packages using package.json

14 |

Part 1 of Free Code Camp Backend Challenges

15 |
16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | /****************************************************** 2 | * PLEASE DO NOT EDIT THIS FILE 3 | * the verification process may break 4 | * ***************************************************/ 5 | 6 | 'use strict'; 7 | 8 | var fs = require('fs'); 9 | var express = require('express'); 10 | var app = express(); 11 | 12 | if (!process.env.DISABLE_XORIGIN) { 13 | app.use(function(req, res, next) { 14 | var allowedOrigins = ['https://narrow-plane.gomix.me', 'https://www.freecodecamp.com']; 15 | var origin = req.headers.origin || '*'; 16 | if(!process.env.XORIG_RESTRICT || allowedOrigins.indexOf(origin) > -1){ 17 | console.log(origin); 18 | res.setHeader('Access-Control-Allow-Origin', origin); 19 | res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); 20 | } 21 | next(); 22 | }); 23 | } 24 | 25 | app.use('/public', express.static(process.cwd() + '/public')); 26 | 27 | app.route('/_api/package.json') 28 | .get(function(req, res, next) { 29 | console.log('requested'); 30 | fs.readFile(__dirname + '/package.json', function(err, data) { 31 | if(err) return next(err); 32 | res.type('txt').send(data.toString()); 33 | }); 34 | }); 35 | 36 | app.route('/') 37 | .get(function(req, res) { 38 | res.sendFile(process.cwd() + '/views/index.html'); 39 | }) 40 | 41 | // Respond not found to all the wrong routes 42 | app.use(function(req, res, next){ 43 | res.status(404); 44 | res.type('txt').send('Not found'); 45 | }); 46 | 47 | // Error Middleware 48 | app.use(function(err, req, res, next) { 49 | if(err) { 50 | res.status(err.status || 500) 51 | .type('txt') 52 | .send(err.message || 'SERVER ERROR'); 53 | } 54 | }) 55 | 56 | //Listen on port set in environment variable or default to 3000 57 | const listener = app.listen(process.env.PORT || 3000, function () { 58 | console.log("Node.js listening on port " + listener.address().port); 59 | }); 60 | 61 | --------------------------------------------------------------------------------