Sitepoint Email Course on Angular JS 6

I am taking an “email course” from Sitepoint about the Angular platform. Is this a place where I can post questions about it?

                          Thanks!

The instructions in my course say to
create a javascript file named fakeData.js, with some code that will generate sample data.

Question 1: Where should I store this file?

My directory structure is currently:
NodeWork > angular-express-jwt > backend > node_modules
(The package.json file is in “backend”. “node_modules” has lots of subdirectories)

I think this new file should be placed in NodeWork > angular-express-jwt > backend
right next to the package.json file (?)

Then the instructions say to:
add a generate script to package.json:
"scripts": {
"generate": "node fakeData.js > database.json"
},

To populate database.json with data, run:

npm run generate

Question 2: It sounds like those first three lines should be inserted into the file package.json.
Is that correct? Does it matter where I put them?
(The package.json file is not empty. In fact, it already contains a clause:
“scripts”: {
“test”: “echo “Error: no test specified” && exit 1”
},
So should this new script line be added just below the test line, inside
the scripts curly brackets? (combining it so as to have just one more line
in the existing scripts clause,)
or should I insert a second separate “scripts” clause?)

Hi,

Sure, this is a good place to ask questions about the Angular email course.

Unfortunately, it’s difficult to answer your question without seeing what you are seeing. Where did you sign up for the course? I don’t see one on Angular.

image

And which lesson does this happen in?

1 Like

Pullo, thanks for your willingness to help. I signed up for this email course straight from an advertisement email from SitePoint. The list looks much like the one in your image clip.
Here’s the list that was in my email. I went for course #4 in the list, “Build a Real-World App with Angular”. It is being sent from Ahmed Bouchefra.

image

Anyway, this thread is essentially a suggestion to Ahmed that at least for one not-very-savvy user, his instructions were too vague here. But I have guessed at the answers to my questions and it seems to have worked out. So to answer my own questions about Ahmed’s Lesson 1:

  1. I placed the javascript file fakeData.js in the directory
    NodeWork > angular-express-jwt > backend
    right next to the package.json file

  2. After reading more about package.json in the npm documentation, I see that in package.json
    you just need one entry for all of your scripts. So I added to this entry, so it became:

    "scripts":
      { "test": "echo \"Error: no test specified\" && exit 1"
      , "generate": "node fakeData.js > database.json"
      },
    

If you make two scripts entries, I have no idea if there are any bad
implications, but it seemed to work fine as far as I tested it.

Thanks, I found the course. It was here: https://www.sitepoint.com/email-courses/build-a-real-world-app-with-angular/

I’m glad you got your immediate problem sorted, but I signed up for this one too, in case you run into any problems down the road. This way, I’ll be in a better position to help.

You can make as many entries as you need. No bad implications. You can also delete the generic “test” script if you don’t need it.

Thanks, Pullo, very kind of you to help !

I figured I could learn Angular all by itself, and that still may be true, assuming I get far enough into this course to get things set up to support it. But I am sensing that it might be a good idea to take a couple of side trips to learn more about node and also npm .

Anyway, after I got over the above questions and got a little farther, I did indeed have more issues.

I got through the steps almost to the end of the lesson. I entered “npm start”. I issued that command, just like I issued other npm commands, in a “command.exe” window on my Windows 7 PC. But I did not see any result of the “console.log(‘Server running …’) " when I issued it. So it may not be working. Also, when I open a browser and type http://localhost:3000, all I get is " This site can’t be reached”.

I would go on to try the cURL calls, but I’m on a Windows PC, not a linux machine, so when I type that into command.exe, I just get :

  the term 'curl' is not recognized as the name of s cmdlet, function, script file, or operable program ...

I may have to download something to get curl on a Windows PC, but I don’t think the service is running anyway.

I may need help to troubleshoot this.

Hi,

No worries :slight_smile:

This is a very good idea. I would highly recommend reading the following:

as you will run up against Node/npm in almost every JavaScript framework you use.

Yup, something’s not correct here, so let’s take a step back. You are at the end of lesson 1, correct?


Can you first conform which version of Node and npm you have installed?

What output does running the following commands produce?

node -v
npm -v

Next, what is the contents of your package.json file?

It should look like this:

{
  "name": "backend",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "generate": "node fakeData.js > database.json",
    "start": "node server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "faker": "^4.1.0",
    "json-server": "^0.14.0",
    "jsonwebtoken": "^8.3.0"
  }
}

Finally, what is your directory tree like?

It should be like this:

angular-express-jwt
└── backend
    ├── database.json
    ├── fakeData.js
    ├── node_modules
    │   └── Lots of files and folders...
    ├── package.json
    ├── package-lock.json
    └── server.js

Don’t do this, use Postman. But we’ll get to that when we have solved your initial problem :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.