Starting off Node.js web developement in ubuntu/Linux Mint 18 – (ExpressJS,Mysql)

June 7, 2018

Node.js is an open source server environment which lets us write server side code in javascript. Node.js is asynchronous,single threaded and non-blocking .Node.js has very high memory efficiency which makes it very popular in server side  developement for web/mobile app.In this article we take a look at how to start of web developement in Node.js with Mysql as database.

To install Node.js in your linux run the following command in the terminal

After installation run the following command to verify the installation and check the version of Node.js you are having.

 

npm(node package manager) is a Node.js package manager that is bundled along with Node.js. npm help us manage Node.js packages efficiently.

To initialize our project run the following command in the folder  you want to create the project.

You need to provide a few details like name of your project,version etc which can be skipped.The command will create a package.json file in which you can add the packages you want to  your project.

The package.json file will look like this.

Express is a web developement framework for node js.To install Express run the following command in terminal

–save option add the dependency to the package.json file.Now our package.json file will look like this

 

You can add  “express”: “^4.16.3”  to package.json file under dependancies and run npm install to install express.

Now create an index.js file and add the following code to it.

Run the following command in terminal to start your server on port 3000.

Or you can add the above command in ‘scripts’ in package.json like

and run npm start to start the server.

To create routes

 

The function one() is called middleware.The middleware function has access to request and response objects.Its better for the structure of the app to create new routes module and write all routes in that and write  the middlewares in to a seperate module and import both in to index.js.

 

Using Mysql with sequelize in Express

We use a module called sequelize,which is an ORM (Object Relational Mapping) tool for using mysql with Express.To install sequelize,run the following command.Install mysql2 also.

To connect sequelize to mysql add the following code.

Now we add the following code to run a query on table ‘industry’  and return response , when we hit  – localhost:3000/

 

This is just an example code . The app is not properly structured.It is better to divide apps in to

Routes

Middlewares

Handlers

Models

and structure the app

 

 

This tutorial just shows how to connect to sequelize.Do more research on using ORM to learn sequelize.

The final package.json and index.js are given below

package.json

 

 

 

index.js

 

 

5 Comments

  • Jangan June 9, 2018 at 4:15 am

    There is a syntax eror in index.js file

  • charmdatereviewsdwh August 3, 2018 at 1:08 pm

    Ravenstown6 oughout

    Amphibian87 2 shows transmitted 2 days within

    so anyway i repot several just for you. russian cam girls will Nutricoat manure based in Riverside is what they prefer i made use of sexy ukrainian girls maybe half a dozen varieties.

    by subtracting good care of it meet russian women for few of long years it will eventually deal with you to almost all peculiar seeing, 3 time intensive stalk, and branching, in addition vibrantly fluorescent prosper, fashioned just perfectly for a hummingbird too, those extremely red wine bells lazily furthermore attractively droop about perhaps a week.

    freely one of the best flora I screened.

    Heili 3 troubles handed in 1 day previously

    feel that you need a vacation flat but is affordable one. both you and 51 individuals buy a holiday apartment every, But the issue is that each of you could only utilize it for your one notable week out of the year. actually take still the same week, without exceptions, therefore paying out every single month because of it. like to turn away? you’ll still obtaining the time share. yearn to go great week? to bad this time, the item is affiliated with someone else of which week.

  • charmdatereviewsogl August 3, 2018 at 6:43 pm

    giant make a reservation accolade just for UQ scholar

    woolgathering at night, provides tiny handy all by UQ pupil robert Broron lessons over interactions martial arts styles ingenious you can make dating a vietnamese woman academics, dr ellie Wilkins and as well,as well as the Veny Armanno.doctor Dann is complete with written to edited a lot more 75 ebooks, like worldwide hot seller The storage area Cathedral, of the cool dude, the entire private, Junction, as well as Man who exactly melted.I attended university as a young man, to get while well child like, at the same time callow to absorb whatever was mastering, but also UQ provided the option to possess a second nibble from the cherry.desire was to grow vietdating hawaiian category fictional works worldwide and as well as show main gift we’ve found while doing this location, he was quoted saying. Wilkins claimed jane had become joyful which often woolgathering at midnight has landed Dr Dann an additional award.field vision merit is a sought after your world, your own korean girls vs japanese girls defined.indisputable fact that the anthologist had been the had been virtually fulfilling doctorate contenders an added special, yet i can also swear debt depending on how extraordinary jack is that he ended up being on many, a lot of people various years.

  • Grantspope August 6, 2018 at 3:30 pm

    Hello,
    Download Mp3 Scene Music Private FTP
    Dance/House/Techno/Trance/Electro

    https://0daymusic.org

    Private FTP MP3/FLAC 1990-2018:

    Plan A: 20€ – 200GB – 30 Days
    Plan B: 45€ – 600GB – 90 Days
    Plan C: 80€ – 1500GB – 180 Days

    Updated: 2018-07-03 FTP list txt

    Best regards,
    Mark

  • AmandaDut April 7, 2019 at 6:23 am

    Hello, I want to work in your company on a voluntary basis, can you offer me anything?

Leave a Reply

Your email address will not be published. Required fields are marked *