Tutorials: NodeJS and ExpressWhile learning about Express and and how to use, here is my small effort to document my learning in tutorial form. Express has become an integral part in web applications developed in NodeJS.
Tutorial 1: NodeJS: An Asynchronous World
Tutorial 2: Express: Middleware or more...
Tutorial 3: Understanding Routing in Express
Tutorial 4: Develop a Static File Server
Tutorial 5: Using HTTPS with Express
Tutorial 6: Develop an JSON API server
Tutorial 7: Use Templates and Views with Express
Tutorial 8: Integrating MongoDB
Tutorial 9: Testing Express Applications
Tutorial 10: Securing Express
- Its execution is fast (V8 JS engine being compined in C++)
- Promotes asynchronous coding style
- Same coding paradigm for front and back end.
Installing NodeJSThe simplest way is go to NodeJS website and click on the installer link. The site also provides other download options (binary download or installers for Mac and Linux flavours). For Windows make sure your machine has latest OS updates otherwise windows installer may have trouble in installing.
For Linux, nodeJS package manager (eg apt-get) is also available. The installer also installs node package manager (npm). Once installed you can check node version and npm version by typing node -v and npm -v respectively at the command prompt or shell.
First NodeJS ProgramYou can try your first the most famous "Hello World" program in nodeJS. Type the following script in notepad or any text editor and save the file as helloworld.js
To run this code type node helloworld.js at the shell prompt. If everything works well, you would see the output of the program similar to what is shown in the figure.
console.log() api is part of console built-in module in nodeJS. There are many inbuilt modules (or libraries) and globals defined in nodeJS. Apart from using builtin modules, you can use external modules.
Node Package Manager or npm helps you installing or managing node modules. The site www.npmjs.com lists the most starred packages used among NodeJS community.
Let us try to install and use colors module. The colors module gives color style to your console output. Type npm install colors will download colors module from npm repository and installs it. You can see a directory named 'node_modules' gets created where npm installs any package.
|npm install color|
See the following snippet showing how to use 'colors' node module: