40

I have quite recently started to connect a web platform that I work on to other quite complex systems mostly written in C#. Most of my experience is in web development in PHP and JavaScript And I also have some experience in writing web services in WCF.

Sadly I had experienced many difficulties in writing WCF services for my PHP web platform, slow development, very (very) complicated configurations in-order to respond well in JSON and to work RESTful and more.

Naturally I started looking around at other technologies, one in particular caught my eye Node.js which might be perfect for me because I have quite a lot of experience in JavaScript and that way I won't need my windows server anymore. My other option is of course to keep writing services in C# but switch to ASP.NET Web API instead. The switch will probably be much easier than from WCF to Node.js.

Any thoughts or suggestions in the matter? Does anyone have experience in writing web services in Node.js and can point me in the direction of a good tutorial? or am I way off and I shouldn't be using Node.js for web services at all?

1

4 Answers 4

48

I have just recently started working on express.js. Let me tell you it's not for the fainthearted. The whole mentality of "If you are already familiar with JS then that's half the battle." really couldn't be further from the truth. I.E. if you are a hardcore devops guy like me.

I have a unified build process for all my asp.net application build, test and coverage reporting, deployment, configuration management and code quality analysis all setup and automated. It takes me literally 5 min to setup a Build process around a new project and have it tested, analysed, staged and shipped off to a production environment. (And really so should all the devs in the world. But hey, who am I kidding.) Then there's the monitoring, logging, performance analysis and profiling. Again all well unified, orchestrated and centrally managed.

I'm not saying node.js/express.js doesn't have those, but you have to develope/learn a COMPLETELY NEW set of services and platform just to run node.js.

Hammering out a bunch of code is one thing. Running a production system on a foreign technology is something else altogether.

Unless you looking for trouble ahem i mean, challenge :D, stick to WebAPI. WebDeploy is a god send.

BTW. Use BasicHttpBinding with your WCF endpoint and get PHP to generate the client class from the WSDL. Yes. Soap is your answer, not an "easier to use rest". Something like https://code.google.com/p/php-wsdl-creator/. Archiving the WSDL from the WCF endpoint also allows you to track with pin point accuracy of your service signature and format changes. It ensures type safety, and handles ser/de for you. I don't care much about how ugly the message looks if I don't have to deal with it. And yes I have done it before with PHP and python. Works flawlessly.

Sign up to request clarification or add additional context in comments.

8 Comments

I agree with most of whats said here, except the bit where your saying SOAP is the answer. Better of writing a proper REST API in .NET Web API, forget about SOAP unless you specifically need it to support legacy apps that already are designed to talk SOAP
@Marty you obviously don't work with WSDL/code generation/type safety. There's nothing proper about "REST API" in a private SOA environment. You can argue "human readability" all you want. When I have hundreds of service endpoints, what I want is a checksum over wsdl to systematically pinpoint changes.
I think the problem is most people think JS is a relatively simple language because, in most cases, the extent of their usage is making their webpages dance (usually with a helping hand from jQuery). The switch to Node requires more than that, you need to embrace JS at it's purest (e.g. single-threaded, callbacks, scoping etc.) and be strict with your development - it's as much as a mindset change as it is a technology one.
Your point on having to learn new services & tools goes the same way if you are coming from a non-ASP.NET background (which the OP appears to be), however, once you set it up once it's just like riding a bike.
@James yes, missed that too. The paradigm is completely different. I'm from ASP.Net too and scoping/callback required some getting used to. I'm still in the process of learning best practices too. Even tho I can write applications and stuff, doesn't mean it's done "right".
|
27

After 10 years of .net development, I wanted to use Nodejs for a mid sized application. I am Just sharing my experience.

Windows footprint

Most of the new apps are deployed in cloud today. For a Asp.net we need windows, though it works on Linux using mono, I am not confident enough about performance. Windows server alone requires more than 750mb of ram, I wanted deploy my app on 1 GB memory server to reduce the cost. So I wanted tiny OS. Linux is proven for it. In this case Linux wins, hence node js. However I believe Windows Nano Server can address this in near future. Now .Net (core) runs on linux

.Net Core

Now .net core is the next Node JS. It has open the door for C# to run on Linux and Mac. Unity, Xmarin allows to create mobile apps and games too. We can now create .net standard library that can work on .net core, framework, xmarin and Unity.

Best time for C# developers.

Quicker to code

I can code well in C# as well as on js. So this is not a problem for me...

Code clarity

This is an important area. When the code base grows everything get complex in JavaScript. One person’s javascript may not readable to another person. Many .net projects has large codebase but it is easily readable and Debuggable. A normal skilled team can manage C# codes in better manner. For node js the team has to be highly skilled in JS. Average programmer may not read JavaScript properly.

Simplicity

nodeJS is very simple, No dlls, no GAC, No classes. It is tiny, really tiny code. But "Code Clarity" is important for me than the number of lines I write. For me simplicity means easy to read, not quicker to code. I feel C# is simpler than JS when the code base grows.

Performance

This is debatable. I feel I can write good performance apps using both the technology.

Open Source libraries

Nodejs wins here. Too many packages, it is like tons of varieties in your breakfast. It was hard for me to choose what I want. I spent a week on ORM libraries for NodeJS, looked around Sequlizer, Sails, Knex, all of them is great. But there are people completely re-coded their app from one framework to other. That clearly shows that every framework is missing something. This never happened to me in .net world. I am happy with Dapper, and Service stack ORM lite.

But we have more choice in node js, so if we choose properly everything is going to be fine.

Docker

Docker is cool one. Who will say “I don’t want it”? This is the main thing I wanted for windows. I heard Microsoft already doing something. We have to wait and see…

Platform portability

Node js can run on almost on any OS, so what? I am going to use one type of OS. AWS provides very few variations of linux. For me it doesn’t matter what OS my app requires, my worry is how much cost it is. In this case Windows and Linux are almost same priced by cloud providers. The only reason I like linux is It has very small footprint. Windows is not. As I mentioned Windows Nano will address this. So I am Ok to run my app on windows server.

Now .Net core runs on linux so in docker.

Finally I decided to use C# and web api. The main reason is my existing experience on it. However I will look back to node js for my next app.

No more look back. Will continue with C# for server side, and react JS for client side.

1 Comment

FYI, Windows Server 2016 has nano server, which use about 90 percent less resources than full Windows Server, Also has Containers (Including Docker), etc.. and of course .NET core runs natively on Linux (not under mono), so most of your arguments while correct 6 months ago and somewhat correct today, won't be in a few months. License cost is still an issue though.
20

Both platforms have their pros & cons and, ultimately, both will do the job.

However, having used both, for me Node.js would win hands down for simplicity, development/deployment speed and performance which you get out of the box - and if it doesn't come out of the box, most likely there's a package for it.

Node has been around for a few years now, however, it's only recently started to become more popular - so much so that Microsoft have vastly improved the tooling support in VS.

2 Comments

How about the switch? How much can I depend on the fact that I know regular JS pretty well when switching to Node.js? How different are they?
@itaywss If you are already familiar with JS then that's half the battle. However, as with any framework there are some concepts/best practises you will need to learn along the way. For me, I found the transition pretty painless.
1

What about the need for cross-platform portability? What if the need is for having web api/REST services that can be deployed on both Windows and Linux servers?

WCF - I don't think it can go to Linux (yet) (mongo??) WebAPI - Can't go to Linux (I think??) NodeJS - Cross platform runtime available. Code once deploy anywhere. xyz - What else do we have that can provide all these?

At least because of this, I would suggest the op for NodeJS

1 Comment

You think wrong. .NET core has WebApi that runs natively on Linux, and Mac (not using Mono either). WCF, yes that isn't portable.. yet.. but maybe soon. Still, WebApi is very capable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.