DeveloperBreeze

Backend Development Development Tutorials, Guides & Insights

Unlock 11+ expert-curated backend development tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your backend development skills on DeveloperBreeze.

Connecting a Node.js Application to an SQLite Database Using sqlite3

Tutorial October 24, 2024

Create a JavaScript file named app.js in your project directory and open it in your preferred code editor.

touch app.js

MySQL Cheatsheet: Comprehensive Guide with Examples

Cheatsheet August 20, 2024
mysql

No preview available for this content.

Integrating Laravel and React with Vite: Using Databases and PHP in a Full-Stack Project

Tutorial August 14, 2024
javascript php

Ensure that Vite is configured to handle React in your project:

   npm install react react-dom

Building a RESTful API with Go and Gorilla Mux

Tutorial August 12, 2024
go

Start the server by running the following command in your terminal:

go run main.go

Building a GraphQL API with Node.js and Apollo Server

Tutorial August 12, 2024
javascript nodejs graphql

const { ApolloServer, gql, PubSub } = require('apollo-server-express');
const pubsub = new PubSub();

const BOOK_ADDED = 'BOOK_ADDED';

const typeDefs = gql`
    type Book {
        title: String!
        author: String!
    }

    type Query {
        books: [Book]
    }

    type Mutation {
        addBook(title: String!, author: String!): Book
    }

    type Subscription {
        bookAdded: Book
    }
`;

const resolvers = {
    Query: {
        books: () => books,
    },
    Mutation: {
        addBook: (_, { title, author }) => {
            const newBook = { title, author };
            books.push(newBook);
            pubsub.publish(BOOK_ADDED, { bookAdded: newBook });
            return newBook;
        },
    },
    Subscription: {
        bookAdded: {
            subscribe: () => pubsub.asyncIterator([BOOK_ADDED]),
        },
    },
};

const server = new ApolloServer({
    typeDefs,
    resolvers,
    subscriptions: {
        path: '/subscriptions',
    },
});

const app = express();
server.applyMiddleware({ app });

const httpServer = require('http').createServer(app);
server.installSubscriptionHandlers(httpServer);

httpServer.listen({ port: 4000 }, () => {
    console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
    console.log(`🚀 Subscriptions ready at ws://localhost:4000${server.subscriptionsPath}`);
});

In the GraphQL Playground, you can test the subscription by running the following: