Tag Archives: node.js

JavaScript – start with TypeScript .

About TypeScript is an open-source language and compiler that runs both in the browser  -through SystemJS  and on NodeJS.
Is developed by Microsoft, like an open-source language and compiler that runs both in the browser through SystemJS and on NodeJS.
Now TypeScript compiles to clean, simple JavaScript code.
You can runs on any browser, in Node.js, or in any JavaScript engine that supports ECMAScript 3 (or newer).
There are two main ways to get the TypeScript tools:

  • using npm (the Node.js package manager)
  • or installing TypeScript’s Visual Studio plugins

The easiest way to get started with TypeScript is through the TypeScript playground found on the TypeScript website play.
The TypeScript version 2.4 has already introduced dynamic import expressions, safer callback parameter checking, weak types, and string enums.
About dynamic import expressions then allows users to asynchronously request a module at any arbitrary point in your program.
The string enums allows enum members to contain string initializers.
Allow to return types as inference targets can now make inferences for the return type of a call.
To get started with the latest stable version of TypeScript, you can grab it through NuGet with:

You can use the following command with npm:

Also you can download it from official website.
To compile it use this:

Now, let’s install it and try it.
First use git command to put into your computer:

Make a file named ts_es001.ts and use this command:

The result will be : ts_es001.js file.
Create your ts_es001.html file with this content:

This is most simple example of using typescript tool with node.js .

Posted in All, javascript, node.js, Programming. Tagged with , , , , , .

Make firefox addon with node.js and jpm – part 001.

Download the npm from nodejs official website.
Run the windows downloaded program and make your testing directory and run the npm:

The next step is to run the instalation of jpm with this:

Will see also the folders where is the new jpm.
To make your addons you need to login into your firefox dev account and take one generate API credentials.
Then run this commands and fill with data the new addon, like you can see in the next example:

I have this files into my folder free-tutorials.org_addons:

The my_user is my user and you will have the name of your user.
Use the next command to build an XPI.

Into this moment the addon is not signed. If you use about:config will see this:
npm_jpm_addon_signature
Use this link to submit the addon. You need to upload your XPI file and also to follow the steps from mozilla website.
When you done the you can see your addon.
My default example addon version 0.0.1 can be found here: free-tutorials.org addon.
The addon is not signed yet so will need to set xpinstall.signatures.required to false from about:config if you want to install it.
I will make another tutorial about how to do the signed process.

Posted in All, node.js, Programming, web, Windows 10. Tagged with , , , , , , , , , , , .

Simple webpage with node.js and express framework – part 001

First you need to see my first tutorial about node.js and express from default-web-application-with-express-framework-and-node-js.

Now after you make all settings from tutorial will go to the next step.

Let see versions of : node and npm :

Now will need to test to default express page (like in the last tutorial).

When you running nodemon you can type rc command to restart the child process and Ctr+C to stop it.

I will use Jade sintax for webpage and Stylus to generate stylesheets.

We need to make some changes… Go to views folder and will see two file:

Let’s it’s index.jade will not change now…

…and another named layout.jade this will be changed. See default file:

Now change the content of layout.jade will be like this:

After each change will be need to restart child process (in test001 folder not from another folder):

The webpage will be like this:

express-nodejs-001

You can see also this file in the source code : /stylesheets/style.css .

Use the next commands to see stylesheets files:

I’m using Stylus so then open the style.styl (not style.css) file.

The content of the file is :

Now we need to change the stylesheet with this. You can try anything else if you like it.

The result will be like this…

express-nodejs-002

We see also I have tree links : Home , About and Contact.

Will need to link all to the app.js to make working well.

This is default content of app.js file:

Now is need to routing this links. Something like routing in Sinatra.

The app.js will become ( see my comments from // my changes to //end my changes ):

Will need to make all of this pages if not will get this error: 500 Error.

Go to views folder and make two empty file named about.jade and contact.jade .

To about.jade file add this text:

… and also change the contact.jade file with this source code:

The result will be this :

express-nodejs-003
express-nodejs-004

Posted in All, node.js, Programming. Tagged with , , , , .

Default web application with express framework and node.js .

Express3.0.0 is a web application framework for node.js.

Today I will show you how to set this framework.

Try to see if the node.js and npm running on your machine.

Install express

Let’s create an express application with stylus for css ( see -c arg ).

You’ll need to install dependencies of this application.

You can open http://127.0.0.1:3000 to see the default Express page.

Let’s see the results:

node.js express framework

Posted in All, node.js, Programming. Tagged with , , , , .

Working with node.js and nodemon – part 001

Node.js is a platform for easily building fast, scalable network applications.

Download the archive from here.

Unarchive and you can use it.

The nodemon can be use during development of a node.js based application.

How? will watch the files in the directory that nodemon was started.

Also it will automatically restart your node application if it’s some changes.

Using nodemode is very easy.

You need to install nodemode using npm.

Now nodemon will be installed in to your bin path.

If you got some errors about : /usr/bin/env node then you need to add the module.

Add your node_modules to the PATH.

if you use the folder in your home account then edit .bashrc and add this:

or maybe you can try :

See my examples. In my bin node folder and I add to the PATH:

Try the nodemon module.

For more information, take a look at the documentation here

Posted in All, node.js. Tagged with , , , , , .