New language every year?

Posted on July 20, 2015

New language every year? Maybe something you already know.

Nowadays we have many things to care about while developing web applications. There are a lot of frameworks which helps us with those complications and cover most of the problems for us, but sometimes they force you to do things that are time-consuming and not really needed. So, didn’t you dream about something simple and light, something that let’s you write your own code, but aswell covers some aspects which could be hard to implement? There is a simple solution called JavaScript. In this article I won’t focus on Node.js amazing aspects such as working in real-time, and I/O operations, but on simple everyday development.


Switching from PHP to JavaScript
If you’re providing REST applications with JSON as main data structure, switching from PHP to JavaScript shouldn’t be very difficult. You can gain a lot of productivity while using JavaScript across the stack. Unified language for both frontend and backend, with unified JSON data format and unified async paradigm is simply magical.

Changing your favourite programming language to JavaScript could make a big difference if you’re using ‘legacy’ PHP, and might be pretty simple change for ‘modern’ developers.

You can ask yourself  how long does it take for you to create simple CRUD endpoint in your language. It can be pretty simple if you’re using some lightweight PHP frameworks like Laravel, but it’s even simpler with minimalist super-fast Node.js framework called Express:

    app.get(‘/data’, function(req, res){

  res.sendStatus(200);

}).post(‘/data’, function(req, res){

  res.sendStatus(200);

}).put(‘/data’, function(req, res){

  res.sendStatus(200);

}).delete(‘/data’, function(req, res){

  res.sendStatus(200);

});

That’s all you need to write. Amazing, isn’t it? I know it’s not much different from Laravel, but come on, JavaScript syntax is just cooler. 😉


 

Power of NPM

 

NPM (acronym for Node Package Manager) brings you almost everything you need. Amount of packages you can install is just ridiculous, and while there are still much more PHP SDK’s they just doesn’t feel like up to date. With NPM you can expect solution for almost everything you can imagine for modern web development. While with composer installing packages is something you’re doing by compulsion, with NPM everything is cool, fast, feels like you’re connecting with JavaScript community.


 

NoSQL database with Node.js

 

So another thing to take look at is database. There is no better feeling in the world than switching from boring long queries written in some kind of SQL after setting up database tables and connecting with it from your code to simple Mongoose model with just one line of connection.

 

mongoose.connect(‘mongodb://localhost:27017/your_db);

 

Yes, that’s all you need to do, to create table, connect to database, and have it ready to use. And then just simple model.

 

var UserSchema = new Schema({

  name: String,

  username: {type: String, required: true, index: {unique: true}},

  password: {type: String, required: true, select: false}

});

 

Magic. I know most of you are using some ORM’s to relational databases, and there are cases where NoSQL is not the best solution, but think about all the projects you could implement with NoSQL while saving time and effort.


 

 

Conclusion

While there is much more for me to explore in JavaScript, I can recommend you switching to this language, and when you’re using frontend based on JavaScript (there are many frameworks for you to choose), and you just need to write some CRUD actions in your API, then JavaScript is in my opinion the best solution. It’s fast, simple, lightweight and cool. Don’t hate it, just try it.

Would you like to know more about Appformation’s work and get all the new articles? Please join our free newsletter now!

 

 

Michał Chudziak

Junior PHP Developer