3 ms·
Setting up new applications in Java or .NET is by far easier than Node.JS I'm far from a node fan, but that is simply not true. When it comes to going from ze
by dagw 10y ago
Setting up new applications in Java or .NET is by far easier than Node.JS
I'm far from a node fan, but that is simply not true. When it comes to going from zero to a "Hello World" webapp (super simple rest api that grabs data from db and returns as JSON) nothing really beats node in my opinion.
Install npm, npm install express (or restify), npm install database-driver (and there are drivers for everything), type a dozen lines of code into a single file and you're done. Sure npm is probably doing some crazy things with dependencies in the background, but you don't have to worry about it to just get started.
Doing the same with Java or C# is much more involved.
Of course going from there to a large complete application is far from equally trivial and I definitely prefer working in something else in most cases, but node has the whole getting started experience down pat and that's probably the reason it's become so popular.
- kuschku 10y agoMuch more involved? With Java and co it’s literally the same. You add two dependencies to your gradle, write a dozen lines of code, and you’re done. Even if you go full enterprise it’s not much more. Let’s go full Java Enterprise: // Enterprisify everything! compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.5.0.RELEASE' compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.11.0.RELEASE' compile group: 'org.springframework.data', name: 'spring-data-commons', version: '1.13.0.RELEASE' // persistence framework compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.0.Final' // database driver compile group: 'org.postgresql', name: 'postgresql', version: '9.4.1212' // to auto-generate getters, setters etc. compileOnly "org.projectlombok:lombok:1.16.16" Now we’ve imported spring, our database driver and an ORM. Let’s write the code. First, let’s config: // application config spring.application.name=ourapp server.port=8090 // database config spring.datasource.url=<our database url> spring.datasource.username=<username> spring.datasource.password=<password> spring.datasource.driver-class-name=org.postgresql.Driver Then add the database layer, defining our model: @Entity @Table // To auto-generate mapping for the ORM @Getter @Setter // To auto-generate getters and setters public class Book { @Id private long id; @Column private String name; @Column private String description; } And our access layer: public interface BookRepository extends CrudRepository<Book, Long> { Optional<Book> findById(long id); } And our application: @RestController @SpringBootApplication @EnableJpaRepositories public class OurApplication { @Autowired private BookRepository books; @RequestMapping(path = "/{id}") public Optional<Book> getBookById(@PathVariable long id) { return books.findById(id); } public static void main(String[] args) { SpringApplication.run(OurApplication.class, args); } } So. This is if you go full insanely Java Enterprise, want full Spring, and everything. If you choose sanely, it’s obviously far less code. Notice how I don’t have to use any transpilers, etc, and still get typing and the latest language features.