Content Creator Contracting Project Help - How to start

I’m currently on the Content Creator Contracting Project and I have absolutely no idea how to begin.(https://www.codecademy.com/paths/create-a-back-end-app-with-javascript/tracks/bapi-javascript-conditionals-and-functions/modules/developing-javascript-apps-locally/informationals/bapi-p0-content-creators)

I am also unsure of what the question is asking for. Thus, I need help with:

  1. Understanding the question better
  2. Starting the project and having a guided step

Appreciate any help given here!

7 Likes

Hello community, I am also lost. I installed a couple of software dev kits (git, node.js, visual studio code) and got lost afterwards. The instructions in the project say …

“To run these tests, first open the root project directory in your terminal. Then run npm install to install all necessary testing dependencies (you will only need to do this step once). Finally, run npm run test. You will see a list of tests that ran with information about whether or not each test passed. After this list, you will see more specific output about why each failing test failed.”

… so I opened Visual Studio Code and opened the project on highest level in terminal and typed in ‘npm install’ - the terminal showed the following error message:

  • CategoryInfo : ObjectNotFound: (npm:String) , CommandNotFoundException
  • FullyQualifiedErrorId : CommandNotFoundException

Am I in the wrong dev kit, or on the wrong hierachy level?

Appreciate any help given here,
Max

Solved the problem by trail and error. Unpacked downloaded data in C:/users/username and opened with node.js command prompt by entering ‘npm install’ . It’s a bit messy, because data is without a folder, but it worked. It returned some test feedback after ‘npm run test’. I guess next step is to fix the reported problems.
@codeacademy : would be good to add some additional hints in the task

1 Like

I’m shocked with the insane lack of clarity in how to do this. NOT helpful. No video. No step by step. No checks to help you understand what you’re supposed to do.
No quiz, no screenshot. Nothing.

2 Likes

Hi @jononovo, did @method7493314847 's response here help you at all? I’m raising your concerns to our content improvement team.

I’m in the same stage of the course experiencing the same unclarities.
Looking at the solution code, the objective is more clear.
Here is how i interpret the instruction:

you will need to implement the functionality for determining content types for 'text/html', 'text/css', 'image/jpeg', and 'text/plain'. For more information on this functionality, run the testing suite (detailed below).’

I interpret this as:
‘run a succesful testing suite, and you will get some kind of clarity about what to do .’

This is where it goes wrong, since the installation of the ‘npm install’ test suite already gives a bunch of error’s . This problem actually starts 2 articles before the start of the project. I have just opened a topic about this:

Whats missing is a proper instruction on setting up the test suite, and what a functioning test setup should look like / the result of a fully funtioning npm test or npm run test.

I still don’t know if i have the right setup?

when i try npm run test in either the -start or -solution version of this project, i get the following error message:

pm ERR! content-creators@1.0.0 test: mocha

npm ERR! spawn ENOENT

npm ERR!

npm ERR! Failed at the content-creators@1.0.0 test script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:

npm ERR! /Users/arejas/.npm/_logs/2020-03-17T23_57_37_384Z-debug.log

I hope you can answer my question and improve the content :slight_smile: so far i have been very satisfied with the courses.

cheers
Michiel

1 Like

Hello alyssavigil,

I agree with the other students in this thread in that this project is very difficult to grasp. This project throws you into the deep end without question.

If I can suggest more practical and working knowledge around Mocha, Chai and bash (the articles provided are very high level and not sufficient) before expecting students to run it in command line.

An example I can give you is ‘npm run test’ gave me a whole lot of code in bash that was entirely unfamiliar, and Codecademy had not provided the requisite knowledge to know what I was looking for in a successful/unsuccessful test (it took me ages to figure out that it wasn’t even running the test, and I needed to install mocha and Chai manually for some reason. No idea why ‘npm install’ didn’t work).

Once I got the test working, I had no idea where to start to solve each test. Which I think is a lack of understanding of the problem being solved (what is the getContentType () actually supposed to do, and why?).

Up to this point, the path is exceptional and I feel like I’m learning quickly. Keep it up.

Thanks!

2 Likes

Can confirm, I am also having trouble. Started out fine - was able to npm install and npm run test and actually got the five test cases to show in the bash console, with the first test already validated (it’s a ‘gimme’ that comes with the downloaded code.)

Fooled around a bit in the console with the project before going to bed. Woke up today to work on this project some more, and after disconnecting from wifi and restarting my computer, the npm run test no longer works! instead I get a huge error message (below):

$ npm run test

content-creators@1.0.0 test C:\Users\BR\desktop\code_projects\content_creators_contracting
mocha

evalmachine.:33
getContentType(filename);
^

ReferenceError: filename is not defined
at evalmachine.:33:16
at Script.runInThisContext (vm.js:120:20)
at Object.runInThisContext (vm.js:311:38)
at Object. (C:\Users\BR\desktop\code_projects\content_creators_contracting\test\test.js:6:4)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\mocha\lib\mocha.js:334:36
at Array.forEach ()
at Mocha.loadFiles (C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\mocha\lib\mocha.js:331:14)
at Mocha.run (C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\mocha\lib\mocha.js:809:10)
at Object.exports.singleRun (C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\mocha\lib\cli\run-helpers.js:108:16)
at exports.runMocha (C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\mocha\lib\cli\run-helpers.js:142:13)
at Object.exports.handler (C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\mocha\lib\cli\run.js:292:3)
at Object.runCommand (C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\yargs\lib\command.js:242:26)
at Object.parseArgs [as _parseArgs] (C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\yargs\yargs.js:1113:24)
at Object.parse (C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\yargs\yargs.js:575:25)
at Object.exports.main (C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\mocha\lib\cli\cli.js:68:6)
at Object. (C:\Users\BR\Desktop\code_projects\content_creators_contracting\node_modules\mocha\bin\mocha:162:29)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! content-creators@1.0.0 test: mocha
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the content-creators@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\BR\AppData\Roaming\npm-cache_logs\2020-04-21T23_49_10_708Z-debug.log

So yeah, I have no idea how to get the testing to work now, because like everyone has pointed out before the whole “learn chai and mocha” was very high level. And to be frank, I felt like I was just kind of thrown into testing without having the babysteps I was used to.

I did eventually figure out what the project wanted of me, (instructions were SUPER confusing), but now I don’t feel right skipping it without passing the Mocha/Chai tests. This lesson definitely needs to be looked at and get fleshed out further.

I have been doing great up until now but this project has become a total roadblock to me. I don’t want to skip it because I’m a completionist but I truly don’t even know where to begin.

HELP!

3 Likes

I’m in the exact same situation, it’s a bit of an insane jump from what we were learning before and a complete overload of new concepts that are explained pretty poorly to be honest.

Where have you got to so far? I’ve managed to open the program on Visual Studio Code and can see the different sections of code, and have managed to run a test in the console that makes no sense to me whatsoever, these are the results:

sam@Sam MINGW64 ~/Documents/project 0
$ npm run test

content-creators@1.0.0 test C:\Users\sam\Documents\project 0
mocha

getContentType()
√ a function called getContentType should exist
1) should return “text/html” for filenames ending in .html
2) should return “text/css” for filenames ending in .css
3) should return “image/jpeg” for filenames ending in .jpeg
4) should return “image/jpeg” for filenames ending in .jpg
5) should return “text/plain” for all other file extensions

1 passing (170ms)
5 failing

  1. getContentType()
    should return “text/html” for filenames ending in .html:
    AssertionError: expected undefined to equal ‘text/html’
    at Object.should.equal (node_modules\chai\lib\chai\interface\should.js:97:35)
    at Context. (test\test.js:16:12)
    at processImmediate (internal/timers.js:456:21)

  2. getContentType()
    should return “text/css” for filenames ending in .css:
    AssertionError: expected undefined to equal ‘text/css’
    at Object.should.equal (node_modules\chai\lib\chai\interface\should.js:97:35)
    at Context. (test\test.js:20:12)
    at processImmediate (internal/timers.js:456:21)

  3. getContentType()
    should return “image/jpeg” for filenames ending in .jpeg:
    AssertionError: expected undefined to equal ‘image/jpeg’
    at Object.should.equal (node_modules\chai\lib\chai\interface\should.js:97:35)
    at Context. (test\test.js:24:12)
    at processImmediate (internal/timers.js:456:21)

  4. getContentType()
    should return “image/jpeg” for filenames ending in .jpg:
    AssertionError: expected undefined to equal ‘image/jpeg’
    at Object.should.equal (node_modules\chai\lib\chai\interface\should.js:97:35)
    at Context. (test\test.js:28:12)
    at processImmediate (internal/timers.js:456:21)

  5. getContentType()
    should return “text/plain” for all other file extensions:
    AssertionError: expected undefined to equal ‘text/plain’
    at Object.should.equal (node_modules\chai\lib\chai\interface\should.js:97:35)
    at Context. (test\test.js:32:12)
    at processImmediate (internal/timers.js:456:21)

npm ERR! code ELIFECYCLE
npm ERR! errno 5
npm ERR! content-creators@1.0.0 test: mocha
npm ERR! Exit status 5
npm ERR!
npm ERR! Failed at the content-creators@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\sam\AppData\Roaming\npm-cache_logs\2020-05-05T22_07_01_539Z-debug.log

Just to follow on from the above… I’ve been looking at it a bit more and focussing on what comes up when I do the test in the console I get:

getContentType()
√ a function called getContentType should exist
1) should return “text/html” for filenames ending in .html
2) should return “text/css” for filenames ending in .css
3) should return “image/jpeg” for filenames ending in .jpeg
4) should return “image/jpeg” for filenames ending in .jpg
5) should return “text/plain” for all other file extensions

The task also says that ‘All of your code should be written in js/request-logic.js.’

Opening the request-logic.js file in Visual Code gets us this:

// We at Content Creators know this code is useful for getting the

// extension off of the supplied filename, but we can’t figure out the rest of

// the function to use it! We hope this is useful to you!

function getContentType(filename) {

const extension = filename.match(/..([^.])$/)[1];

}

So the function getContentType is there and exists, which is why the test checked it off, but it doesn’t do anything. We have to make it do the five things listed above I guess, only problem is, I’ve never seen a .match before and this bit (/..([^.])$/)[1]; looks like complete jargon to me.

Will carry on trying to crack it I guess

Wow! You’ve gotten much further than me. I have opened the index.html page and loaded it in VSC. I can’t seem to get the NPM Test to run. I think you are on the right track. I just wish there was a video accompanying it. I’ve been doing well being able to follow and example and then adjust as needed.

I hope you get it! Keep me posted if you figure out a secret!
MT

I don’t think I got the test to run the way you’re supposed to to be fair. I opened up the project in my file explorer and then right clicked on the folder, there was a button to ‘Git Bash Here’ which then opened it up in the console.

I’m not sure if this is the done thing but since we’re both stuck on the same task I’d be happy to work through it together, just shoot me an email at TellySavalas365@gmail.com if you fancy that, otherwise I’ll just update on here

Well I completed it finally,

I tried

function getContentType(filename) {

const extension = filename.match(/..([^.])$/)[1];
return ‘text/html’
}

and then tested it using npm run test.

I then got

getContentType()
√ a function called getContentType should exist
√ should return “text/html” for filenames ending in .html
1) should return “text/css” for filenames ending in .css
2) should return “image/jpeg” for filenames ending in .jpeg
3) should return “image/jpeg” for filenames ending in .jpg
4) should return “text/plain” for all other file extensions

2 passing (11ms)
4 failing

After going back and looking over if/else statements I worked it out from there.

Good luck and feel free to email me anyway, could be good to bounce off someone at the same level.

1 Like

After an hour of struggling, I think I finally got it.
First, I used the Visual Studio code to open the folder I just uncompressed, and found the request-logic.js file under the js folder.

Then I wrote:

function getContentType(filename) {

const extension = filename.match(/..([^.])$/)[1];

/since it already gave you the variable ‘extension’ which will give you the last string, I figured just set the variable equal to what we want/

if (extension === ‘html’) {

return 'text/html';

} else if (extension === ‘css’) {

return 'text/css';

} else if (extension === ‘jpg’) {

return 'image/jpeg';

} else if (extension === ‘jpeg’) {

return 'image/jpeg';

} else {

return 'text/plain';

};

}
Then I ran the folder under Git Bash (right click the same folder and click Git Bash Here) and tested it using “npm run test”, this is what I got:

content-creators@1.0.0 test C:\Users\user\Downloads\project-0-content-creators-start
mocha

getContentType()
√ a function called getContentType should exist
√ should return “text/html” for filenames ending in .html
√ should return “text/css” for filenames ending in .css
√ should return “image/jpeg” for filenames ending in .jpeg
√ should return “image/jpeg” for filenames ending in .jpg
√ should return “text/plain” for all other file extensions

6 passing (6ms)

Finally I checked my demo (open the uncompressed folder and click the one name “index” with a chrome logo on it.) It worked just like the final version so I think I made it! I hope this help you guys too!

p.s. I am a high school student from Taiwan and I just joined this community recently! Please let me know if there’s any mistakes I made, whether it is coding-wise or some grammar mistakes during the interpretation! Have a great day coding y’all!

2 Likes

Did u install mocha or chai in ur computer before any of this??
Bcoz the first thing i get, when i run npm run test in Git Bash is this line followed by multiple other errors as discussed above…

'mocha' is not recognized as an internal or external command,
operable program or batch file.

So, do we have to intall mocha first??

I did not. all I did was opened the file in the git bash and typed “npm install.” I think that is how you install mocha but I might be wrong.

Came here to see how folks were getting on with this. I can’t believe how much of a jump this exercise is! Oh well, I guess it’s good to be chucked into the real world!

Here are some pointers which might help. The exercise is actually pretty straightforward, but does benefit from a bit of explanation:

  1. Make sure you’ve set up Bash (if you’re on Windows), Node.js and Visual Studio Code. The videos are pretty comprehensive, but if you don’t have them set up, you’re not getting anyway.
  2. Download and unzip the folder from Codecademy somewhere sensible.
  3. Open VS Code and select File>Add Folder to Workspace. Navigate to the folder from Codecademy and add it. This is good practice for working on these projects.
  4. Open up Bash and navigate to the folder. Top tips: pwd will show you what directory you’re in right now. ls will show you the contents of the folder. Use cd <foldername> to navigate. cd .. will take you backwards.
  5. After navigating to the folder from Codecademy in Bash, type npm install. This will download the necessary files to your project folder.
  6. Type npm run test to run the tests. You’ll see it fails on a bunch of things.
  7. In VS Code, find the ‘request-logic.js’ file in the ‘js’ folder of the workspace.
  8. Your task is just to edit the function in that folder so that it returns the right output. For clarity, const extension = filename.match(/.*\.([^\.]*)$/)[1]; is a line of code which will take the filename parameter the function received and remove everything except the extension at the end of the filename. This means the variable ‘extension’ will be equal to html, css, jpeg, jpg or nothing. You need to write an if/else statement which will return ‘text/html’, ‘text/css’, ‘image/jpeg’ or ‘text/plain’ depending on the input. Save your file.
  9. In Bash, enter npm run test and your tests should complete.

Hope that helps a little. Hit me up with a reply if it doesn’t make sense .

2 Likes

no you are right, it was installed by npm install and then we had to run npm run test and it worked the magic, Anyway thanks for the reply :slightly_smiling_face:
this project was really simple just had to see the tests and apply all the testing suite into it and there you go.

1 Like

At least from my tests, it looks like if you don’t create the project0 directory (unzipping from the project zip file) from your user’s actual home directory, the npm commands will fail, and constantly.
I had a deep directory structure where my study files were deep in /home/sina/host/Codecademy/BackendAppWithJavaScript/Projects/project0
and I’ve been stuck trying different things for nearly a week.