Day 96 MEAN Full Stack Review

Hello coders the same grind going on today of working and listening to the Node.js course from the beginning again.

First of all a full stack developer is a developer who knows all the pieces of a software stack. They can build software by themselves if need be. This is the goal to become a full stack developer to truly be a builder.

In the course we look at an example simple app to see what is happening on the server and what is happening on the client.

The first example was taking an array in the public front end JavaScript and placing it in the Node.js app. This was a copy so that the array was in the public JavaScript front end folder and on Node. So now the array is on the client and server.

EJS and in general for view engines and template engines I can pass an object with data that can be used by Express in order to render HTML.

Then I changed the people array in the server to serverPeople and that is the name and the value is the people array. So when Node runs this page and goes to render index.ejs the object will be available.

Then in the index.ejs file I wrote another script tag to take data from the server and make it available to the client. This is possible by combining JavaScript on the client with JavaScript being run on the server. The script tag will implement EJS by making a var clientPeople with EJS code <%- %>. Then the argument I wanted was to output string, so inside the argument I put in JSON.stringify( ). This is built into JavaScript and basically means to take an object and output as JSON. Inside the stringify argument will be serverPeople.

At this point I have a script tag, client side JavaScript, but injecting a piece of server side template code. Which runs server side JavaScript, that takes my array and outputs it as JSON. The client side code will end up as new code generate by EJS.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Up ↑

%d bloggers like this: