separate from any Galvanize forked & cloned project //so that your .git stuff is not mixed up with their .git stuff
-
$ npm init -y//creates package.json which allows you to set-up your project dependencies--js libraries for your project
//create a start script in your package.json:
"start": "node app.js"//it may also be required to make sure that your "main" a couple lines above is like so:
"main": "app.js", -
$ npm install express cors body-parser convert-csv-to-json//don't use express generator for now
//gives access to Cross Origin Resource Sharing
-
$ touch app.jsin the app.js file:
const express = require("express") //knows to go look in node_modules const app = express( ) const cors = require('cors') const csvToJson = require('convert-csv-to-json') //example code: csvToJson.fieldDelimiter(',').getJsonFromCsv(file_name.csv); const port = process.env.PORT || 9000 //The "pocess.env.PORT" part is for heroku port variable that they assign app.listen(port, ( ) => { console.log('I am listening on ${port}') }) //single quotes above in console.log statement should actually be backticks in the code
-
$ npm startor$ nodemon//to get the server running
-
-in app.js file:
app.use(cors( ));
//now I'll be able to actually use cors
-
-in app.js file:
const bodyParser = require('body-parser') app.use(bodyParser.json( )) app.get( '/', (request, response, next) => { })
- new repository
$ touch .gitignore- paste in .gitignore instructions from "the last .gitignore you'll ever need"
$ git init//creates .git directory in your project folder$ git remote add origin (url to repo)$ git add -A//to stage all the files that you have created but not yet pushed to github repo (only do this after the .gitnore file has been created and populated, esp. with the node-modules file to be ignored)$ git commit -m "first commit"$ git push -u origin master