Storing & retrieving Data in the CPU

To start with you need to have Node installed, if you do not have it use this: Link

Starting the Project:

Now crate a Directory this directory will have the “Blue-Prints” that node will use to build the App, make sure to “Terminal” “cd abc” into the directory, there initialize npm using the command:

Here is where node will ask you few questions, about the project that you are initializing, if you do not want to answer the question just press “Enter” and Node will use the default answer which you can see in parenthesis, then Node will pass to ask the next question.

The last question will ask you to review the answer that you just give, and if you say OK, it will create a JSON file with that information. (you can edit this file latter.)

Now if you see the directory you will see that Node just create a file named: “package.json” that file has the configuration parameters for your App, this is also the place were we will be storing the 3rd party libraries that we require, so each time that we use this “Blue-Prints” to build our App Node will make sure to check this file to see what other Library  or  Module, or Dependency  it has to bundle when building the app.

Next we will install a Module that will allow-us to store data Locally into our computer, this module name is:  node-persist witth the commad: npm install node-persist@0.0.6 –save

Let me explain what just happen, here Node it tells you that will install the Module: node-persist then it tells you that this module in order to work needs to install other modules and tells you the name of those modules, the version and Install them.

You will also notice  that thanks to the flag  ” –save  ” this will modify your JSON file.

You will also notice that it create a new folder named: “node_modules” inside you can find a folder for each module installed, also the ones that you do not install but the got installed as a requirement to a module you install.

Create Script to Start the APP  “app.js”:

In the directory create a new file and name it: app.js  and add the code: ” console.log(“Starting Edxael’s Passwor Manager”); ” and save it.

Then lest modify our JSON file. in the section of “scripts” we will add a new script that will be executed when we use the command: “ npm start “.

Remember we create the file “app.js” lest add this script to the list of scripts executed when we run the “npm start” command.

Now when we run the “npm start” command in the Terminal, code in the “app.jswill be executed.

—————————

Storing & retrieving Data in the CPU:

here we will get data and store this data in a file in the computer.

1st – To do this we will use the Module that we install “node-persist” to be able to to use it we will require it and store it in a variable in our “app.js” file:

Basic example in how to create a variable that is stored in the computer:

Another example, in this case we create a variable that will be the database for the Bank Accounts:

Now lest add one more account:

  1. Load the Browser var ‘dbase‘ with the current data in the CPU var: ‘accounts
  2. Add the new account to the Browser variable: ‘dbase
  3. Sync the data in ‘dbase‘ with the CPU variable ‘accounts

Then the next time that you need to get the data from the CPU:

 

 

 

 

.



Copyright 2017. All rights reserved.

Posted June 16, 2017 by Edmundo in category "Node