Ubuntu – Setup jQuery project with node.js and server from scratch

Yup! That is what we are gonna do – Setup jQuery project with node.js and server from scratch in Ubuntu. There are plenty of ways to do it in the internet.

Setting up a jQuery project is something, that should be automated and trivial enough not to bother with it all, but yet, there are some important lines to write in the command prompt of Ubuntu to achieve it.

So, here it goes, open the prompt, navigate to the file where you want to nest your project and type:

>>> mkdir Desktop/JS/Week_5/Pro1 (not needed, if you have navigated)
>>> touch server.js (creates server.js).

In the created file put the following:

With the current one, you will access the local host on port 3000. If you want another port, change the 3000 from the code to something else.

>>> npm init
>>> npm install –save express
>>> mkdir public; touch public/index.html
>>> npm install semver
>>> npm install jsonfile –save
>>> sudo npm install -g bower
>>> bower install –save jQuery

In the html file, you should define the location of the jquery.min.js. Take a look where it is and simply move it in a way to be in the following directory: public/lib/bower_components/jQuery/dist/jquery.min.js

Then, in your index.html file, you may refer to jquery the following way:

<script src=”lib/bower_components/jQuery/dist/jquery.min.js”></script>

If you want to avoid moving folders, you may create a file “.bowerrc” in your root directory (“Pro1” in my case) and enter the following data before installing bower:

Finally you can run the server with the following:

>>> node server.js

The terminal should reply with something like this:

Example app listening at http://0.0.0.0:3000

Last but not least, if you want to take a look of the generated files, visit my repository here.

This is a screenshot of the project:

ToDoList

Enjoy it and have a nice evening!

About

VBA Developer

Tagged with: , , , , , ,