Professional Documents
Culture Documents
Node JS, Loopback 3 Complete Installation, With Model Generation Script - by - Hemantham
Node JS, Loopback 3 Complete Installation, With Model Generation Script - by - Hemantham
My moto
Hello, world..!! I’m always, Happy to write…Living to Code. I would like to share my
experience with Loopback, One among the best Nodejs frameworks so far.
Prerequisites
Step_1
Step_2
Step_3
# lb <project_name>
Step_4
Now it’s time to move faster. Because it is it, Just hit enter, in response to the command
prompts. Remember to choose loopback 3.x , Since the title sounds it. sorry for guys
who looking for loopback 4.x, and congratulations to guys who are looking for
loopback 2.x, because of the installation steps which are almost the same.
https://medium.com/@hemantham002/node-js-loopback-3-complete-installation-with-model-generation-script-eafcbc68f1b2 2/9
03/04/2020 Node js,Loopback 3 complete installation,with model generation script-:by_hemantham
Simply select empty-server(An empty loopback API, without any configured models or
datasources…..as shown in the above picture)
Step_4
Step_5
When you see the above screen, it’s a clean installation of loopback project and you are set to go o
further.
https://medium.com/@hemantham002/node-js-loopback-3-complete-installation-with-model-generation-script-eafcbc68f1b2 3/9
03/04/2020 Node js,Loopback 3 complete installation,with model generation script-:by_hemantham
Step_6
Feel free to explore the project directory, And create a folder bin inside the folder
server. And inside bin folder create a js file discover_dbmodels.js
server/bin/discover_dbmodels.js
# Paste the below code in it ..
. . .
const fs = require(‘fs’);
https://medium.com/@hemantham002/node-js-loopback-3-complete-installation-with-model-generation-script-eafcbc68f1b2 4/9
03/04/2020 Node js,Loopback 3 complete installation,with model generation script-:by_hemantham
discover().then(
success => {
console.log(‘\n’)
console.log(‘# table ->’ + args.t + ‘ from # database ->’ + args.d + ‘ has been loaded
succesfully..!!’)
process.exit()
},
error => {
process.exit(1);
);
const options = {
relations: true
};
await mkdirp(‘common/models’);
dbtable[key].properties.id.required = false;
config[cap_Fir_Let_] = {
dataSource: DATASOURCE_NAME,
public: true
};
await writeFile(
‘server/model-config.json’,
JSON.stringify(config, null, 2)
);
await createIfNotExist(
model_JS_file,
);
Step_7
https://medium.com/@hemantham002/node-js-loopback-3-complete-installation-with-model-generation-script-eafcbc68f1b2 6/9
03/04/2020 Node js,Loopback 3 complete installation,with model generation script-:by_hemantham
Don’t forget to choose mysql connector from the prompts.Use arrow keys to move up and down
this is my datasource, just answer to the prompts with correct values and cli generates datasource.json for
you in server/datasource.json
Step_8
https://medium.com/@hemantham002/node-js-loopback-3-complete-installation-with-model-generation-script-eafcbc68f1b2 7/9
03/04/2020 Node js,Loopback 3 complete installation,with model generation script-:by_hemantham
where table_name and database_name are command line arguments sent to discover_dbmodels.js le
for generating models
Step_9
Generate all the tables in your database one by one by running the above script. You
guys might have got a doubt ,What if there are hundreds of tables in my database,should i
have to run all of them one by one? And that’s an amazing doubt checkout my another
article in which i added a script for auto-generating all the database tables at once with
one command. The name of the article follows the same this article has but comes with
auto-generate_allTables.
once u are done with models generation ur done with the command line with this last
step
# npm start
You would see the following result in the cmd
You are all done with loopback installation…now try the magics provided by loopback
at this screen below
https://medium.com/@hemantham002/node-js-loopback-3-complete-installation-with-model-generation-script-eafcbc68f1b2 8/9
03/04/2020 Node js,Loopback 3 complete installation,with model generation script-:by_hemantham
When you see your models here..then it’s a clean end of installation
That’s it guys… if you want line by line explaination of what the above
discover_dbmodels.js script does, check out my next article. It’s name would be
probably
https://medium.com/@hemantham002/node-js-loopback-3-complete-installation-with-model-generation-script-eafcbc68f1b2 9/9