# Install Cosmic CLI
npm i -g cosmic-cli
# Login to your Cosmic JS account
cosmic login
# Installs example content to a new or existing Bucket and downloads the app locally
cosmic init node-starter
cd node-starter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.js | |
const api = require('cosmicjs')(); | |
const bucket = api.bucket({ | |
slug: 'simple-react-blog', | |
read_key: '' // Find this in Bucket > Settings > API Access after logging in https://app.cosmicjs.com/login | |
}) | |
export async function getStaticProps() { | |
const post = (await bucket.getObject({ | |
slug: 'a-wonderful-blog-post-about-earth' | |
})).object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get Object by Metafield Object ID | |
const run = async () => { | |
const Cosmic = require('cosmicjs') | |
const api = Cosmic() | |
const bucket = api.bucket({ | |
slug: 'cosmic-js' | |
}) | |
const data = await bucket.getObjects({ | |
type: 'articles', | |
limit: 20, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"objects": [ | |
{ | |
"slug": "a-wonderful-blog-post-about-earth", | |
"title": "A Wonderful Blog Post About Earth", | |
"content": "<p>When I orbited the Earth in a spaceship, I saw for the first time how beautiful our planet is. Mankind, let us preserve and increase this beauty, and not destroy it!</p><p>Space, the final frontier. These are the voyages of the Starship Enterprise. Its five-year mission: to explore strange new worlds, to seek out new life and new civilizations, to boldly go where no man has gone before.</p><p>If you could see the earth illuminated when you were in a place as dark as night, it would look to you more splendid than the moon.</p><p>To be the first to enter the cosmos, to engage, single-handed, in an unprecedented duel with nature—could one dream of anything more?</p><p>We choose to go to the moon in this decade and do the other things, not because they are easy, but because they are hard, because that goal will serve to organize and measure the best of our energi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"objects": [ | |
{ | |
"_id": "59df6dd5fd8d731b21001191", | |
"bucket": "59df6dcbfd8d731b21001188", | |
"slug": "a-wonderful-blog-post-about-earth", | |
"title": "A Wonderful Blog Post About Earth", | |
"content": "<p>When I orbited the Earth in a spaceship, I saw for the first time how beautiful our planet is. Mankind, let us preserve and increase this beauty, and not destroy it!</p><p>Space, the final frontier. These are the voyages of the Starship Enterprise. Its five-year mission: to explore strange new worlds, to seek out new life and new civilizations, to boldly go where no man has gone before.</p><p>If you could see the earth illuminated when you were in a place as dark as night, it would look to you more splendid than the moon.</p><p>To be the first to enter the cosmos, to engage, single-handed, in an unprecedented duel with nature—could one dream of anything more?</p><p>We choose to go to the moon in this decade and do the other things, not because they are easy, but because they |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.js | |
const fs = require('fs') | |
const Cosmic = require('cosmicjs')() | |
const multer = require('multer') | |
const express = require('express') | |
var app = express() | |
const bucket = Cosmic.bucket({ | |
slug: 'your-bucket-slug', | |
write_key: '' | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<video id="myVideo" controls></video> | |
<!-- Use HLS.js to support the HLS format in browsers. --> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | |
<script> | |
(function(){ | |
// Replace with your asset's playback ID | |
var playbackId = "oIdQlddn3YGhfCK00Mkj0169KMArk2s701Q"; | |
var url = "https://stream.mux.com/"+playbackId+".m3u8"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
siteMetadata: { | |
title: 'Cosmic JS Gatsby Starter Localization', | |
nav: [ | |
{ slug: '', name: 'Home' }, | |
{ slug: 'about', name: 'About' }, | |
{ slug: 'contact', name: 'Contact' }, | |
{ slug: 'not-found', name: 'Not Found' }, | |
], | |
languages: [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://unpkg.com/[email protected]/cosmicjs.browser.min.js"></script> | |
<script> | |
var api = new Cosmic(); | |
var bucket = api.bucket({ | |
slug: 'json-bucket' | |
}) | |
bucket.addObject({ | |
title: 'Test Page', | |
type_slug: 'pages', | |
metafields: [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import Router from 'next/router' | |
import bucket from '../config' | |
import Page from '../components/page' | |
import PageNotFound from '../components/404' | |
import Header from '../components/header' | |
import Footer from '../components/footer' | |
import Nav from '../components/nav' | |
class DefaultPage extends React.Component { | |
static async getInitialProps({ req, query }) { |